+- (id<JubChatUI>)chatForContact: (XMPPContact*)contact
+{
+ OFAutoreleasePool *pool = [OFAutoreleasePool new];
+ OFString *bareJID = [contact.rosterItem.JID bareJID];
+
+ id<JubChatUI> 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;
+}
+