gaim/gaim

This should fix the MSN problems with having multiple
oldstatus
2005-02-22, Stu Tomlinson
a1190be55f45
Parents 271835cd313c
Children a28f835ea1ba
This should fix the MSN problems with having multiple
switchboards associated with the same conversation / buddy.
--- a/src/protocols/msn/msn.c Tue Feb 22 10:08:27 2005 -0500
+++ b/src/protocols/msn/msn.c Tue Feb 22 10:16:16 2005 -0500
@@ -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);
@@ -697,7 +696,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);
}
@@ -753,7 +752,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;
@@ -1056,7 +1055,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)
{
@@ -1065,7 +1064,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);
@@ -1076,16 +1074,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
@@ -1100,7 +1109,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;
@@ -1193,10 +1202,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
@@ -1206,10 +1216,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 10:08:27 2005 -0500
+++ b/src/protocols/msn/session.c Tue Feb 22 10:16:16 2005 -0500
@@ -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 10:08:27 2005 -0500
+++ b/src/protocols/msn/session.h Tue Feb 22 10:16:16 2005 -0500
@@ -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 10:08:27 2005 -0500
+++ b/src/protocols/msn/slplink.c Tue Feb 22 10:16:16 2005 -0500
@@ -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 10:08:27 2005 -0500
+++ b/src/protocols/msn/switchboard.c Tue Feb 22 10:16:16 2005 -0500
@@ -867,20 +867,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(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 10:08:27 2005 -0500
+++ b/src/protocols/msn/switchboard.h Tue Feb 22 10:16:16 2005 -0500
@@ -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;