Apply the same fix as a00b7964253b, but for group chats, again resolving a double-retain
authorEvan Schoenberg
Sun, 21 Aug 2011 15:14:33 -0500
changeset 3610 93c8292bc1c8
parent 3609 97743a0ab02c
child 3611 85165a4ab9cb
Apply the same fix as a00b7964253b, but for group chats, again resolving a double-retain
(transplanted from a9560a8f30eb8e61e4a327d42b5376262ad7e30b)
Plugins/Purple Service/SLPurpleCocoaAdapter.m
--- a/Plugins/Purple Service/SLPurpleCocoaAdapter.m	Mon Aug 15 23:19:09 2011 +0200
+++ b/Plugins/Purple Service/SLPurpleCocoaAdapter.m	Sun Aug 21 15:14:33 2011 -0500
@@ -341,12 +341,29 @@
 		NSString *name = [NSString stringWithUTF8String:purple_conversation_get_name(conv)];
 		
 		CBPurpleAccount *account = accountLookup(purple_conversation_get_account(conv));
+        
+        /* 
+         * Need to start a new chat, associating with the PurpleConversation.
+         *
+         * This may call back through to us recursively, via:
+         *   -[CBPurpleAccount chatWithContact:identifier:]
+         *   -[AIChatController chatWithContact:]
+         *   -[CBPurpleAccount openChat:]
+         *   -[SLPurpleCocoaAdaper openChat:onAccount:]
+         *   convLookupFromChat()
+         *   groupChatLookupFromConv()
+         *
+         * That's fine, as we'll get the same lookups the second time through; we just need to be cautious.
+         */
 		chat = [account chatWithName:name identifier:[NSValue valueWithPointer:conv]];
 		if (!chat.chatCreationDictionary) {
 			// If we don't have a chat creation dictionary (i.e., we didn't initiate the join), create one.
 			chat.chatCreationDictionary = [account extractChatCreationDictionaryFromConversation: conv];
 		}
-		conv->ui_data = [chat retain];
+        if (conv->ui_data != chat) {
+            [(AIChat *)(conv->ui_data) release];
+            conv->ui_data = [chat retain];
+        }
 		AILog(@"group chat lookup assigned %@ to %p (%s)",chat,conv, purple_conversation_get_name(conv));
 	}