changeset 10621:fe919915fceb

[gaim-migrate @ 12090] This should fix the MSN problems with having multiple switchboards associated with the same conversation / buddy. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 22 Feb 2005 15:16:38 +0000
parents 17daac7cea91
children 78a43d6e1801
files src/protocols/msn/msn.c src/protocols/msn/session.c src/protocols/msn/session.h src/protocols/msn/slplink.c src/protocols/msn/switchboard.c src/protocols/msn/switchboard.h
diffstat 6 files changed, 73 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/msn.c	Tue Feb 22 15:16:38 2005 +0000
@@ -338,7 +338,6 @@
 	/* TODO: This might move somewhere else, after USR might be */
 	swboard->chat_id = session->conv_seq++;
 	swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat");
-	swboard->flag = MSN_SB_FLAG_IM;
 
 	gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
 							gaim_account_get_username(buddy->account), NULL, GAIM_CBFLAGS_NONE, TRUE);
@@ -739,7 +738,7 @@
 		MsnSwitchBoard *swboard;
 
 		session = gc->proto_data;
-		swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM);
+		swboard = msn_session_get_swboard(session, who);
 
 		msn_switchboard_send_msg(swboard, msg, TRUE);
 	}
@@ -795,7 +794,7 @@
 		return MSN_TYPING_SEND_TIMEOUT;
 	}
 
-	swboard = msn_session_find_swboard(session, who, MSN_SB_FLAG_IM);
+	swboard = msn_session_find_swboard(session, who);
 
 	if (swboard == NULL || !msn_switchboard_can_send(swboard))
 		return 0;
@@ -1082,7 +1081,7 @@
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
+	swboard = msn_session_find_swboard_with_id(session, id);
 
 	if (swboard == NULL)
 	{
@@ -1091,7 +1090,6 @@
 		msn_switchboard_request(swboard);
 		swboard->chat_id = id;
 		swboard->conv = gaim_find_chat(gc, id);
-		swboard->flag = MSN_SB_FLAG_IM;
 	}
 
 	msn_switchboard_request_add_user(swboard, who);
@@ -1102,16 +1100,27 @@
 {
 	MsnSession *session;
 	MsnSwitchBoard *swboard;
+	GaimConversation *conv;
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
+	swboard = msn_session_find_swboard_with_id(session, id);
 
 	/* if swboard is NULL we were the only person left anyway */
 	if (swboard == NULL)
 		return;
 
+	conv = swboard->conv;
+
 	msn_switchboard_close(swboard);
+
+	/* If other switchboards managed to associate themselves with this
+	 * conv, make sure they know it's gone! */
+	if (conv != NULL)
+	{
+		while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL)
+			swboard->conv = NULL;
+	}
 }
 
 static int
@@ -1126,7 +1135,7 @@
 
 	account = gaim_connection_get_account(gc);
 	session = gc->proto_data;
-	swboard = msn_session_find_swboard_with_id(session, id, MSN_SB_FLAG_IM);
+	swboard = msn_session_find_swboard_with_id(session, id);
 
 	if (swboard == NULL)
 		return -EINVAL;
@@ -1219,10 +1228,11 @@
 {
 	MsnSession *session;
 	MsnSwitchBoard *swboard;
+	GaimConversation *conv;
 
 	session = gc->proto_data;
 
-	swboard = msn_session_find_swboard(session, who, MSN_SB_FLAG_IM);
+	swboard = msn_session_find_swboard(session, who);
 
 	/*
 	 * Don't perform an assertion here. If swboard is NULL, then the
@@ -1232,10 +1242,20 @@
 	if (swboard == NULL)
 		return;
 
+	conv = swboard->conv;
+
 	if (!(swboard->flag & MSN_SB_FLAG_FT))
 		msn_switchboard_close(swboard);
 	else
 		swboard->conv = NULL;
+
+	/* If other switchboards managed to associate themselves with this
+	 * conv, make sure they know it's gone! */
+	if (conv != NULL)
+	{
+		while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL)
+			swboard->conv = NULL;
+	}
 }
 
 static void
--- a/src/protocols/msn/session.c	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/session.c	Tue Feb 22 15:16:38 2005 +0000
@@ -45,6 +45,7 @@
 								 gaim_account_get_username(account), NULL);
 
 	session->protocol_ver = 9;
+	session->conv_seq = 1;
 
 	return session;
 }
@@ -144,8 +145,7 @@
 
 /* TODO: This must go away when conversation is redesigned */
 MsnSwitchBoard *
-msn_session_find_swboard(MsnSession *session, const char *username,
-						 MsnSBFlag flag)
+msn_session_find_swboard(MsnSession *session, const char *username)
 {
 	GList *l;
 
@@ -158,8 +158,7 @@
 
 		swboard = l->data;
 
-		if ((swboard->im_user != NULL) &&
-			!strcmp(username, swboard->im_user) && (swboard->flag & flag))
+		if ((swboard->im_user != NULL) && !strcmp(username, swboard->im_user))
 			return swboard;
 	}
 
@@ -167,8 +166,28 @@
 }
 
 MsnSwitchBoard *
-msn_session_find_swboard_with_id(const MsnSession *session, int chat_id,
-								 MsnSBFlag flag)
+msn_session_find_swboard_with_conv(MsnSession *session, GaimConversation *conv)
+{
+	GList *l;
+
+	g_return_val_if_fail(session  != NULL, NULL);
+	g_return_val_if_fail(conv != NULL, NULL);
+
+	for (l = session->switches; l != NULL; l = l->next)
+	{
+		MsnSwitchBoard *swboard;
+
+		swboard = l->data;
+
+		if (swboard->conv == conv)
+			return swboard;
+	}
+
+	return NULL;
+}
+
+MsnSwitchBoard *
+msn_session_find_swboard_with_id(const MsnSession *session, int chat_id)
 {
 	GList *l;
 
@@ -181,7 +200,7 @@
 
 		swboard = l->data;
 
-		if ((swboard->chat_id == chat_id) && (swboard->flag & flag))
+		if (swboard->chat_id == chat_id)
 			return swboard;
 	}
 
@@ -189,18 +208,16 @@
 }
 
 MsnSwitchBoard *
-msn_session_get_swboard(MsnSession *session, const char *username,
-						MsnSBFlag flag)
+msn_session_get_swboard(MsnSession *session, const char *username)
 {
 	MsnSwitchBoard *swboard;
 
-	swboard = msn_session_find_swboard(session, username, flag);
+	swboard = msn_session_find_swboard(session, username);
 
 	if (swboard == NULL)
 	{
 		swboard = msn_switchboard_new(session);
 		swboard->im_user = g_strdup(username);
-		swboard->flag = flag;
 		msn_switchboard_request(swboard);
 		msn_switchboard_request_add_user(swboard, username);
 	}
--- a/src/protocols/msn/session.h	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/session.h	Tue Feb 22 15:16:38 2005 +0000
@@ -160,36 +160,43 @@
  *
  * @param session The MSN session.
  * @param username The username to search for.
- * @param flag The flag of the switchboard.
  *
  * @return The switchboard, if found.
  */
 MsnSwitchBoard *msn_session_find_swboard(MsnSession *session,
-										 const char *username, MsnSBFlag flag);
+										 const char *username);
 
+ /**
+ * Finds a switchboard with the given conversation.
+ *
+ * @param session The MSN session.
+ * @param conv    The conversation to search for.
+ *
+ * @return The switchboard, if found.
+ */
+MsnSwitchBoard *msn_session_find_swboard_with_conv(MsnSession *session,
+												   GaimConversation *conv);
 /**
  * Finds a switchboard with the given chat ID.
  *
  * @param session The MSN session.
  * @param chat_id The chat ID to search for.
- * @param flag The flag of the switchboard.
  *
  * @return The switchboard, if found.
  */
 MsnSwitchBoard *msn_session_find_swboard_with_id(const MsnSession *session,
-												 int chat_id, MsnSBFlag flag);
+												 int chat_id);
 
 /**
  * Returns a switchboard to communicate with certain username.
  *
  * @param session The MSN session.
  * @param username The username to search for.
- * @param flag The flag of the switchboard.
  *
  * @return The switchboard.
  */
 MsnSwitchBoard *msn_session_get_swboard(MsnSession *session,
-										const char *username, MsnSBFlag flag);
+										const char *username);
 
 /**
  * Sets an error for the MSN session.
--- a/src/protocols/msn/slplink.c	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/slplink.c	Tue Feb 22 15:16:38 2005 +0000
@@ -162,11 +162,8 @@
 void
 msn_slplink_add_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall)
 {
-	if (slplink->slp_calls == NULL)
-	{
-		if (slplink->swboard != NULL)
-			slplink->swboard->flag |= MSN_SB_FLAG_FT;
-	}
+	if (slplink->swboard != NULL)
+		slplink->swboard->flag |= MSN_SB_FLAG_FT;
 
 	slplink->slp_calls = g_list_append(slplink->slp_calls, slpcall);
 }
@@ -233,8 +230,7 @@
 		if (slplink->swboard == NULL)
 		{
 			slplink->swboard = msn_session_get_swboard(slplink->session,
-													   slplink->remote_user,
-													   MSN_SB_FLAG_FT);
+													   slplink->remote_user);
 
 			if (slplink->swboard == NULL)
 				return;
--- a/src/protocols/msn/switchboard.c	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/switchboard.c	Tue Feb 22 15:16:38 2005 +0000
@@ -854,20 +854,14 @@
 		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);
-			swboard->flag |= MSN_SB_FLAG_IM;
-		}
 	}
 	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));
-			swboard->flag |= MSN_SB_FLAG_IM;
-		}
 	}
 
 	g_free(body_final);
--- a/src/protocols/msn/switchboard.h	Tue Feb 22 15:10:16 2005 +0000
+++ b/src/protocols/msn/switchboard.h	Tue Feb 22 15:16:38 2005 +0000
@@ -54,8 +54,7 @@
  */
 typedef enum
 {
-	MSN_SB_FLAG_IM = 0x01, /**< This switchboard is used for instant messaging. */
-	MSN_SB_FLAG_FT = 0x02, /**< This switchboard is used for file transfer. */
+	MSN_SB_FLAG_FT = 0x01, /**< This switchboard is being used for file transfer. */
 
 } MsnSBFlag;