]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/JubChatClient.m
b4a1481fb4b76683e7aa039d106abadec4f83fb6
[jubjub.git] / src / core / JubChatClient.m
1 #import "JubChatClient.h"
2
3 @implementation JubChatClient
4 @synthesize connection;
5 @synthesize roster;
6 @synthesize contactManager;
7 @synthesize presence;
8 @synthesize ui;
9
10 - initWithConfig: (JubConfig*)config
11 {
12         self = [super init];
13
14         @try {
15                 connection = [XMPPConnection new];
16
17                 connection.username = config.username;
18                 connection.domain = config.domain;
19                 connection.server = config.server;
20                 connection.password = config.password;
21                 [connection addDelegate: self];
22
23                 roster = [[XMPPRoster alloc] initWithConnection: connection];
24                 [roster addDelegate: self];
25
26                 contactManager = [[XMPPContactManager alloc]
27                                       initWithConnection: connection
28                                                   roster: roster];
29
30                 streamManagement = [[XMPPStreamManagement alloc]
31                     initWithConnection: connection];
32
33                 [connection asyncConnectAndHandle];
34         } @catch (id e) {
35                 [self release];
36                 @throw e;
37         }
38
39         return self;
40 }
41
42 - (void)dealloc
43 {
44         [roster release];
45         [contactManager release];
46         [streamManagement release];
47         [connection release];
48         [presence release];
49
50         [super dealloc];
51 }
52
53 - (void)connection: (XMPPConnection*)connection_
54      wasBoundToJID: (XMPPJID*)jid
55 {
56         of_log(@"Bound to JID: %@", [jid fullJID]);
57
58         [roster requestRoster];
59 }
60
61 -   (void)connection: (XMPPConnection*)connection_
62   didReceivePresence: (XMPPPresence*)presence_
63 {
64         if ([presence_.from isEqual: connection.JID]) {
65                 [ui          client: self
66                   didChangePresence: presence_];
67                 OF_SETTER(presence, presence_, YES, 0);
68         }
69 }
70
71 - (void)rosterWasReceived: (XMPPRoster*)roster
72 {
73         XMPPPresence *pres = [XMPPPresence presence];
74         [pres setStatus: @"Hello from JubJub"];
75         [connection sendStanza: pres];
76 }
77 @end