Mercurial > pidgin.yaz
comparison src/protocols/msn/switchboard.c @ 10773:888d4c328be5
[gaim-migrate @ 12382]
Patch 1149564 from Felipe Contreras:
"[MSN] Cleanups and fixes
I know it fixes a multiple conversation close
notification but it probably fixes more stuff.
I don't know exactly what are the diferences with what
Stu did."
I munged it a bit, to make it compile and stuff.
Please test this, I might have broken it.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 02 Apr 2005 16:38:33 +0000 |
parents | c4cb90065e1d |
children | 58c84363c8ae |
comparison
equal
deleted
inserted
replaced
10772:12aa8ce77077 | 10773:888d4c328be5 |
---|---|
27 #include "notification.h" | 27 #include "notification.h" |
28 #include "utils.h" | 28 #include "utils.h" |
29 | 29 |
30 #include "error.h" | 30 #include "error.h" |
31 | 31 |
32 /* #define MSN_DEBUG_SWBOARD */ | |
33 | |
32 static MsnTable *cbs_table; | 34 static MsnTable *cbs_table; |
33 | 35 |
34 static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, | 36 static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, |
35 MsnMsgErrorType error); | 37 MsnMsgErrorType error); |
36 | 38 |
68 { | 70 { |
69 MsnSession *session; | 71 MsnSession *session; |
70 MsnMessage *msg; | 72 MsnMessage *msg; |
71 GList *l; | 73 GList *l; |
72 | 74 |
73 g_return_if_fail(swboard != NULL); | 75 #ifdef MSN_DEBUG_SWBOARD |
76 gaim_debug_info("msn", "switchboard_destroy: swboard(%p)\n", swboard); | |
77 #endif | |
78 | |
79 g_return_if_fail(swboard != NULL); | |
80 | |
81 if (swboard->destroying) | |
82 return; | |
83 | |
84 swboard->destroying = TRUE; | |
74 | 85 |
75 /* If it linked us is because its looking for trouble */ | 86 /* If it linked us is because its looking for trouble */ |
76 if (swboard->slplink != NULL) | 87 if (swboard->slplink != NULL) |
77 msn_slplink_destroy(swboard->slplink); | 88 msn_slplink_destroy(swboard->slplink); |
78 | 89 |
208 | 219 |
209 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); | 220 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); |
210 swboard->current_users++; | 221 swboard->current_users++; |
211 swboard->empty = FALSE; | 222 swboard->empty = FALSE; |
212 | 223 |
213 /* gaim_debug_info("msn", "user=[%s], total=%d\n", user, | 224 #ifdef MSN_DEBUG_CHAT |
214 * swboard->current_users); */ | 225 gaim_debug_info("msn", "user=[%s], total=%d\n", user, |
226 swboard->current_users); | |
227 #endif | |
228 | |
229 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
230 { | |
231 /* This is a helper switchboard. */ | |
232 if (swboard->conv != NULL) | |
233 gaim_debug_error("msn", "switchboard_add_user: conv != NULL\n"); | |
234 | |
235 return; | |
236 } | |
215 | 237 |
216 if ((swboard->conv != NULL) && | 238 if ((swboard->conv != NULL) && |
217 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) | 239 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) |
218 { | 240 { |
219 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL, | 241 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL, |
224 if (swboard->conv == NULL || | 246 if (swboard->conv == NULL || |
225 gaim_conversation_get_type(swboard->conv) != GAIM_CONV_CHAT) | 247 gaim_conversation_get_type(swboard->conv) != GAIM_CONV_CHAT) |
226 { | 248 { |
227 GList *l; | 249 GList *l; |
228 | 250 |
229 /* gaim_debug_info("msn", "[chat] Switching to chat.\n"); */ | 251 #ifdef MSN_DEBUG_CHAT |
252 gaim_debug_info("msn", "[chat] Switching to chat.\n"); | |
253 #endif | |
254 | |
230 #if 0 | 255 #if 0 |
231 /* this is bad - it causes msn_switchboard_close to be called on the | 256 /* this is bad - it causes msn_switchboard_close to be called on the |
232 * switchboard we're in the middle of using :( */ | 257 * switchboard we're in the middle of using :( */ |
233 if (swboard->conv != NULL) | 258 if (swboard->conv != NULL) |
234 gaim_conversation_destroy(swboard->conv); | 259 gaim_conversation_destroy(swboard->conv); |
245 { | 270 { |
246 const char *tmp_user; | 271 const char *tmp_user; |
247 | 272 |
248 tmp_user = l->data; | 273 tmp_user = l->data; |
249 | 274 |
250 /* gaim_debug_info("msn", "[chat] Adding [%s].\n", | 275 #ifdef MSN_DEBUG_CHAT |
251 * tmp_user); */ | 276 gaim_debug_info("msn", "[chat] Adding [%s].\n", tmp_user); |
277 #endif | |
252 | 278 |
253 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), | 279 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), |
254 tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE); | 280 tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE); |
255 } | 281 } |
256 | 282 |
257 /* gaim_debug_info("msn", "[chat] We add ourselves.\n"); */ | 283 #ifdef MSN_DEBUG_CHAT |
284 gaim_debug_info("msn", "[chat] We add ourselves.\n"); | |
285 #endif | |
258 | 286 |
259 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), | 287 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), |
260 gaim_account_get_username(account), | 288 gaim_account_get_username(account), |
261 NULL, GAIM_CBFLAGS_NONE, TRUE); | 289 NULL, GAIM_CBFLAGS_NONE, TRUE); |
262 | 290 |
270 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_ANY, | 298 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_ANY, |
271 user, account); | 299 user, account); |
272 } | 300 } |
273 else | 301 else |
274 { | 302 { |
275 gaim_debug_warning("msn", "This should not happen!" | 303 gaim_debug_warning("msn", "switchboard_add_user: This should not happen!\n"); |
276 "(msn_switchboard_add_user)\n"); | |
277 } | 304 } |
278 } | 305 } |
279 | 306 |
280 GaimConversation * | 307 GaimConversation * |
281 msn_switchboard_get_conv(MsnSwitchBoard *swboard) | 308 msn_switchboard_get_conv(MsnSwitchBoard *swboard) |
354 | 381 |
355 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) | 382 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) |
356 msg->nak_cb(msg, msg->ack_data); | 383 msg->nak_cb(msg, msg->ack_data); |
357 | 384 |
358 swboard = cmdproc->data; | 385 swboard = cmdproc->data; |
386 | |
387 /* This is not good, and should be fixed somewhere else. */ | |
388 g_return_if_fail(swboard != NULL); | |
359 | 389 |
360 if (msg->type == MSN_MSG_TEXT) | 390 if (msg->type == MSN_MSG_TEXT) |
361 { | 391 { |
362 const char *format, *str_reason; | 392 const char *format, *str_reason; |
363 char *body_str, *body_enc, *pre, *post; | 393 char *body_str, *body_enc, *pre, *post; |
611 const char *user; | 641 const char *user; |
612 | 642 |
613 swboard = cmdproc->data; | 643 swboard = cmdproc->data; |
614 user = cmd->params[0]; | 644 user = cmd->params[0]; |
615 | 645 |
646 #if 0 | |
647 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
648 { | |
649 /* TODO: This is a helper switchboard. It would be better if | |
650 * swboard->conv is NULL, but it isn't. */ | |
651 /* Umm? I think swboard->conv is NULL for all helper switchboards now? */ | |
652 msn_switchboard_destroy(swboard); | |
653 return; | |
654 } | |
655 #else | |
656 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
657 gaim_debug_error("msn_switchboard", "bye_cmd: helper bug\n"); | |
658 #endif | |
659 | |
616 if (swboard->conv == NULL) | 660 if (swboard->conv == NULL) |
617 { | 661 { |
618 /* This is a helper switchboard */ | 662 /* This is a helper switchboard */ |
619 msn_switchboard_destroy(swboard); | 663 msn_switchboard_destroy(swboard); |
620 } | 664 } |
845 else | 889 else |
846 { | 890 { |
847 body_final = body_enc; | 891 body_final = body_enc; |
848 } | 892 } |
849 | 893 |
894 swboard->flag |= MSN_SB_FLAG_IM; | |
895 | |
850 if (swboard->current_users > 1 || | 896 if (swboard->current_users > 1 || |
851 ((swboard->conv != NULL) && | 897 ((swboard->conv != NULL) && |
852 gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) | 898 gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) |
853 { | 899 { |
900 /* If current_users is always ok as it should then there is no need to | |
901 * check if this is a chat. */ | |
902 if (swboard->current_users <= 1) | |
903 gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", | |
904 swboard->current_users); | |
905 | |
854 serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, | 906 serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, |
855 time(NULL)); | 907 time(NULL)); |
856 if (swboard->conv == NULL) | 908 if (swboard->conv == NULL) |
909 { | |
857 swboard->conv = gaim_find_chat(gc, swboard->chat_id); | 910 swboard->conv = gaim_find_chat(gc, swboard->chat_id); |
911 swboard->flag |= MSN_SB_FLAG_IM; | |
912 } | |
858 } | 913 } |
859 else | 914 else |
860 { | 915 { |
861 serv_got_im(gc, passport, body_final, 0, time(NULL)); | 916 serv_got_im(gc, passport, body_final, 0, time(NULL)); |
862 if (swboard->conv == NULL) | 917 if (swboard->conv == NULL) |
918 { | |
863 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_IM, | 919 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_IM, |
864 passport, gaim_connection_get_account(gc)); | 920 passport, gaim_connection_get_account(gc)); |
921 swboard->flag |= MSN_SB_FLAG_IM; | |
922 } | |
865 } | 923 } |
866 | 924 |
867 g_free(body_final); | 925 g_free(body_final); |
868 } | 926 } |
869 | 927 |
1099 void | 1157 void |
1100 msn_switchboard_close(MsnSwitchBoard *swboard) | 1158 msn_switchboard_close(MsnSwitchBoard *swboard) |
1101 { | 1159 { |
1102 g_return_if_fail(swboard != NULL); | 1160 g_return_if_fail(swboard != NULL); |
1103 | 1161 |
1104 /* forget any conversation that used to be associated with this swboard */ | |
1105 swboard->conv = NULL; | |
1106 | |
1107 if (swboard->error != MSN_SB_ERROR_NONE) | 1162 if (swboard->error != MSN_SB_ERROR_NONE) |
1108 { | 1163 { |
1109 msn_switchboard_destroy(swboard); | 1164 msn_switchboard_destroy(swboard); |
1110 } | 1165 } |
1111 else if (g_queue_is_empty(swboard->msg_queue) || | 1166 else if (g_queue_is_empty(swboard->msg_queue) || |
1119 } | 1174 } |
1120 else | 1175 else |
1121 { | 1176 { |
1122 swboard->closed = TRUE; | 1177 swboard->closed = TRUE; |
1123 } | 1178 } |
1179 } | |
1180 | |
1181 gboolean | |
1182 msn_switchboard_release(MsnSwitchBoard *swboard, MsnSBFlag flag) | |
1183 { | |
1184 g_return_val_if_fail(swboard != NULL, FALSE); | |
1185 | |
1186 swboard->flag &= ~flag; | |
1187 | |
1188 if (flag == MSN_SB_FLAG_IM) | |
1189 /* Forget any conversation that used to be associated with this | |
1190 * swboard. */ | |
1191 swboard->conv = NULL; | |
1192 | |
1193 if (swboard->flag == 0) | |
1194 { | |
1195 msn_switchboard_close(swboard); | |
1196 return TRUE; | |
1197 } | |
1198 | |
1199 return FALSE; | |
1124 } | 1200 } |
1125 | 1201 |
1126 /************************************************************************** | 1202 /************************************************************************** |
1127 * Init stuff | 1203 * Init stuff |
1128 **************************************************************************/ | 1204 **************************************************************************/ |