]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/gui/gtk/JubGtkRosterUI.m
Handle closing chat windows, fix a race and a retain cycle in the process
[jubjub.git] / src / gui / gtk / JubGtkRosterUI.m
index 9a2da292a1f68075d0f02e176e2bf0c9efd9b4bb..c5163e1ff0c8387619eb6e54b8458e8fb8087a2d 100644 (file)
@@ -100,26 +100,31 @@ static gboolean refilter_roster(gpointer data)
 -  (void)connection: (XMPPConnection*)connection
   didReceiveMessage: (XMPPMessage*)message
 {
-       JubGtkChatUI *chat = [chatMap objectForKey: [message.from bareJID]];
+       JubGtkChatUI *chat =
+           [chatMap objectForKey: [message.from bareJID]];
        if (chat == nil) {
                OFString * title = [@"Chat with " stringByAppendingString:
                    [message.from bareJID]];
-               chat = [JubGtkChatUI alloc];
-               [[chat initWithTitle: title
-                          sendBlock: ^(OFString *text) {
-                       XMPPMessage *msg =
-                           [XMPPMessage messageWithType: @"chat"];
-                       msg.to = message.from;
-                       msg.body = text;
-                       [connection sendStanza: msg];
-
-                       [chat addMessage: msg.body
-                                 sender: [message.to bareJID]];
-               }] autorelease];
+
+               chat = [[[JubGtkChatUI alloc]
+                   initWithTitle: title
+                      closeBlock: ^{
+                               [chatMap removeObjectForKey:
+                                   [message.from bareJID]];
+                       }
+                       sendBlock: ^(OFString *text) {
+                               XMPPMessage *msg =
+                                   [XMPPMessage messageWithType: @"chat"];
+                               msg.to = message.from;
+                               msg.body = text;
+                               [connection sendStanza: msg];
+                       }
+               ] autorelease];
 
                [chatMap setObject: chat
                            forKey: [message.from bareJID]];
        }
+
        [chat addMessage: message.body
                  sender: [message.from bareJID]];
 }