Index: src/protocols/msn/msn.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/msn/msn.c,v retrieving revision 1.320.2.23 retrieving revision 1.320.2.24 diff -u -p -r1.320.2.23 -r1.320.2.24 --- src/protocols/msn/msn.c 16 Feb 2005 20:12:44 -0000 1.320.2.23 +++ src/protocols/msn/msn.c 22 Feb 2005 15:16:06 -0000 1.320.2.24 @@ -338,7 +338,6 @@ initiate_chat_cb(GaimBlistNode *node, gp /* 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 @@ msn_send_im(GaimConnection *gc, const ch 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 @@ msn_send_typing(GaimConnection *gc, cons 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 @@ msn_chat_invite(GaimConnection *gc, int 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_chat_invite(GaimConnection *gc, int 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 @@ msn_chat_leave(GaimConnection *gc, int i { 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 @@ msn_chat_send(GaimConnection *gc, int id 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 @@ msn_convo_closed(GaimConnection *gc, con { 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 @@ msn_convo_closed(GaimConnection *gc, con 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 Index: src/protocols/msn/session.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/msn/session.c,v retrieving revision 1.24.2.18 retrieving revision 1.24.2.19 diff -u -p -r1.24.2.18 -r1.24.2.19 --- src/protocols/msn/session.c 16 Feb 2005 20:13:02 -0000 1.24.2.18 +++ src/protocols/msn/session.c 22 Feb 2005 15:16:13 -0000 1.24.2.19 @@ -45,6 +45,7 @@ msn_session_new(GaimAccount *account) gaim_account_get_username(account), NULL); session->protocol_ver = 9; + session->conv_seq = 1; return session; } @@ -144,8 +145,7 @@ msn_session_disconnect(MsnSession *sessi /* 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 @@ msn_session_find_swboard(MsnSession *ses 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 @@ msn_session_find_swboard(MsnSession *ses } 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 @@ msn_session_find_swboard_with_id(const M swboard = l->data; - if ((swboard->chat_id == chat_id) && (swboard->flag & flag)) + if (swboard->chat_id == chat_id) return swboard; } @@ -189,18 +208,16 @@ msn_session_find_swboard_with_id(const M } 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); } Index: src/protocols/msn/session.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/msn/session.h,v retrieving revision 1.24.2.10 retrieving revision 1.24.2.11 diff -u -p -r1.24.2.10 -r1.24.2.11 --- src/protocols/msn/session.h 16 Feb 2005 20:13:03 -0000 1.24.2.10 +++ src/protocols/msn/session.h 22 Feb 2005 15:16:14 -0000 1.24.2.11 @@ -160,36 +160,43 @@ void msn_session_disconnect(MsnSession * * * @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. Index: src/protocols/msn/slplink.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/msn/slplink.c,v retrieving revision 1.12.2.12 retrieving revision 1.12.2.13 diff -u -p -r1.12.2.12 -r1.12.2.13 --- src/protocols/msn/slplink.c 16 Feb 2005 20:13:09 -0000 1.12.2.12 +++ src/protocols/msn/slplink.c 22 Feb 2005 15:16:14 -0000 1.12.2.13 @@ -162,11 +162,8 @@ msn_slplink_find_slp_session(MsnSlpLink 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 @@ msn_slplink_send_msg(MsnSlpLink *slplink 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; Index: src/protocols/msn/switchboard.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/msn/switchboard.h,v retrieving revision 1.14.2.8 retrieving revision 1.14.2.9 diff -u -p -r1.14.2.8 -r1.14.2.9 --- src/protocols/msn/switchboard.h 16 Feb 2005 20:13:12 -0000 1.14.2.8 +++ src/protocols/msn/switchboard.h 22 Feb 2005 15:16:16 -0000 1.14.2.9 @@ -54,8 +54,7 @@ typedef enum */ 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;