1 #import "JubChatClient.h"
3 @implementation JubChatClient
4 @synthesize connection = _connection;
5 @synthesize roster = _roster;
6 @synthesize contactManager = _contactManager;
7 @synthesize presence = _presence;
10 - initWithConfig: (JubConfig*)config
15 _chatMap = [[OFMutableDictionary alloc] init];
17 _connection = [XMPPConnection new];
18 _connection.username = config.username;
19 _connection.domain = config.domain;
20 _connection.server = config.server;
21 _connection.password = config.password;
22 [_connection addDelegate: self];
24 _roster = [[XMPPRoster alloc] initWithConnection: _connection];
25 [_roster addDelegate: self];
27 _contactManager = [[XMPPContactManager alloc]
28 initWithConnection: _connection
31 _streamManagement = [[XMPPStreamManagement alloc]
32 initWithConnection: _connection];
34 [_connection asyncConnectAndHandle];
46 [_contactManager release];
47 [_streamManagement release];
48 [_connection release];
55 - (id<JubChatUI>)chatForContact: (XMPPContact*)contact
57 OFAutoreleasePool *pool = [OFAutoreleasePool new];
58 OFString *bareJID = [contact.rosterItem.JID bareJID];
60 id<JubChatUI> chat = [_chatMap objectForKey: bareJID];
63 [@"Chat with " stringByAppendingString: bareJID];
65 chat = [[[[_ui chatUIClass] alloc]
68 [_chatMap removeObjectForKey: bareJID];
70 sendBlock: ^(OFString *text) {
72 [XMPPMessage messageWithType: @"chat"];
74 [contact sendMessage: msg
75 connection: _connection];
79 [_chatMap setObject: chat
88 - (void)connection: (XMPPConnection*)connection
89 wasBoundToJID: (XMPPJID*)jid
91 of_log(@"Bound to JID: %@", [jid fullJID]);
93 [_roster requestRoster];
96 - (void)connection: (XMPPConnection*)connection
97 didReceivePresence: (XMPPPresence*)presence
99 if ([presence.from isEqual: connection.JID]) {
101 didChangePresence: presence];
102 OF_SETTER(_presence, presence, YES, 0);
106 - (void)rosterWasReceived: (XMPPRoster*)roster
108 XMPPPresence *pres = [XMPPPresence presence];
109 [pres setStatus: @"Hello from JubJub"];
110 [_connection sendStanza: pres];