diff src/protocols/msn/switchboard.c @ 10533:ace8cd0de6ea

[gaim-migrate @ 11862] Some minor MSN reorganization from Felipe and a bunch of MSN chat related fixes and improvements from me. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 20 Jan 2005 16:37:14 +0000
parents 1a97d5e88d12
children fed2a7c2471d
line wrap: on
line diff
--- a/src/protocols/msn/switchboard.c	Thu Jan 20 14:40:56 2005 +0000
+++ b/src/protocols/msn/switchboard.c	Thu Jan 20 16:37:14 2005 +0000
@@ -227,9 +227,12 @@
 			GList *l;
 
 			/* gaim_debug_info("msn", "[chat] Switching to chat.\n"); */
-
+#if 0
+			/* this is bad - it causes msn_switchboard_close to be called on the
+			 * switchboard we're in the middle of using :( */
 			if (swboard->conv != NULL)
 				gaim_conversation_destroy(swboard->conv);
+#endif
 
 			cmdproc->session->conv_seq++;
 			swboard->chat_id = cmdproc->session->conv_seq;
@@ -314,7 +317,9 @@
 
 	gaim_debug_info("msg", "Error: Unable to call the user %s\n", passport);
 
-	if (swboard->total_users == 0)
+	/* TODO: if current_users > 0, this is probably a chat and an invite failed,
+	 * we should report that in the chat or something */
+	if (swboard->current_users == 0)
 	{
 		swboard->error = reason;
 		msn_switchboard_close(swboard);
@@ -612,10 +617,14 @@
 		/* This is a helper switchboard */
 		msn_switchboard_destroy(swboard);
 	}
-	else if (swboard->current_users > 1)
+	else if ((swboard->current_users > 1) ||
+			 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT))
 	{
 		/* This is a switchboard used for a chat */
 		gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL);
+		swboard->current_users--;
+		if (swboard->current_users == 0)
+			msn_switchboard_destroy(swboard);
 	}
 	else
 	{
@@ -836,13 +845,22 @@
 		body_final = body_enc;
 	}
 
-	if (swboard->current_users > 1)
+	if (swboard->current_users > 1 ||
+		((swboard->conv != NULL) &&
+		 gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT))
 	{
 		serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final,
 						 time(NULL));
+		if (swboard->conv == NULL)
+			swboard->conv = gaim_find_chat(gc, swboard->chat_id);
 	}
 	else
+	{
 		serv_got_im(gc, passport, body_final, 0, time(NULL));
+		if (swboard->conv == NULL)
+			swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_IM,
+									passport, gaim_connection_get_account(gc));
+	}
 
 	g_free(body_final);
 }
@@ -1080,6 +1098,9 @@
 {
 	g_return_if_fail(swboard != NULL);
 
+	 /* forget any conversation that used to be associated with this swboard */
+	swboard->conv = NULL;
+
 	if (swboard->error != MSN_SB_ERROR_NONE)
 	{
 		msn_switchboard_destroy(swboard);