X-Git-Url: http://cgit.babelmonkeys.de/?p=jubjub.git;a=blobdiff_plain;f=src%2Fcore%2FJubChatClient.m;h=3c563f5e9dd1a9f267b9b09ad63787a8be9de1ea;hp=b4a1481fb4b76683e7aa039d106abadec4f83fb6;hb=4d4a2b07fe52fa2d9e21b697dcf85c73bdd537a9;hpb=92e36a6a8e999e69c1750f1215dfe50ca0088035 diff --git a/src/core/JubChatClient.m b/src/core/JubChatClient.m index b4a1481..3c563f5 100644 --- a/src/core/JubChatClient.m +++ b/src/core/JubChatClient.m @@ -12,8 +12,9 @@ self = [super init]; @try { - connection = [XMPPConnection new]; + chatMap = [[OFMutableDictionary alloc] init]; + connection = [XMPPConnection new]; connection.username = config.username; connection.domain = config.domain; connection.server = config.server; @@ -46,10 +47,44 @@ [streamManagement release]; [connection release]; [presence release]; + [chatMap release]; [super dealloc]; } +- (id)chatForContact: (XMPPContact*)contact +{ + OFAutoreleasePool *pool = [OFAutoreleasePool new]; + OFString *bareJID = [contact.rosterItem.JID bareJID]; + + id chat = [chatMap objectForKey: bareJID]; + if (chat == nil) { + OFString * title = + [@"Chat with " stringByAppendingString: bareJID]; + + chat = [[[[ui chatUIClass] alloc] + initWithTitle: title + closeBlock: ^{ + [chatMap removeObjectForKey: bareJID]; + } + sendBlock: ^(OFString *text) { + XMPPMessage *msg = + [XMPPMessage messageWithType: @"chat"]; + msg.body = text; + [contact sendMessage: msg + connection: connection]; + } + ] autorelease]; + + [chatMap setObject: chat + forKey: bareJID]; + } + + [pool release]; + + return chat; +} + - (void)connection: (XMPPConnection*)connection_ wasBoundToJID: (XMPPJID*)jid {