1 #import "JubChatClient.h"
3 @implementation JubChatClient
4 @synthesize connection;
6 @synthesize contactManager;
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];
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];