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