Mercurial > pidgin
comparison libpurple/protocols/mxit/multimx.c @ 29935:5139aa9b4077
Improve the handling of user's being kicked from MultiMX rooms.
* If it's us being kicked, clear the user-list and close the conversation.
* Otherwise, display a message and remove the user from the user-list.
author | andrew.victor@mxit.com |
---|---|
date | Tue, 11 May 2010 16:28:03 +0000 |
parents | 81ea740f92a4 |
children | 62a544afeda9 |
comparison
equal
deleted
inserted
replaced
29934:40a1111c34d3 | 29935:5139aa9b4077 |
---|---|
140 g_strlcpy(multimx->roomid, roomid, sizeof(multimx->roomid)); | 140 g_strlcpy(multimx->roomid, roomid, sizeof(multimx->roomid)); |
141 g_strlcpy(multimx->roomname, roomname, sizeof(multimx->roomname)); | 141 g_strlcpy(multimx->roomname, roomname, sizeof(multimx->roomname)); |
142 multimx->chatid = groupchatID++; | 142 multimx->chatid = groupchatID++; |
143 multimx->state = state; | 143 multimx->state = state; |
144 | 144 |
145 /* determine our nickname (from profile) */ | |
146 if (session->profile && (session->profile->nickname[0] != '\0')) | |
147 multimx->nickname = g_strdup(session->profile->nickname); | |
148 | |
145 /* Add to GroupChat list */ | 149 /* Add to GroupChat list */ |
146 session->rooms = g_list_append(session->rooms, multimx); | 150 session->rooms = g_list_append(session->rooms, multimx); |
147 | 151 |
148 return multimx; | 152 return multimx; |
149 } | 153 } |
157 */ | 161 */ |
158 static void room_remove(struct MXitSession* session, struct multimx* multimx) | 162 static void room_remove(struct MXitSession* session, struct multimx* multimx) |
159 { | 163 { |
160 /* Remove from GroupChat list */ | 164 /* Remove from GroupChat list */ |
161 session->rooms = g_list_remove(session->rooms, multimx); | 165 session->rooms = g_list_remove(session->rooms, multimx); |
166 | |
167 /* free nickname */ | |
168 if (multimx->nickname) | |
169 g_free(multimx->nickname); | |
162 | 170 |
163 /* Deallocate it */ | 171 /* Deallocate it */ |
164 free (multimx); | 172 free (multimx); |
165 multimx = NULL; | 173 multimx = NULL; |
166 } | 174 } |
207 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); | 215 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); |
208 return; | 216 return; |
209 } | 217 } |
210 | 218 |
211 purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, NULL); | 219 purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, NULL); |
220 } | |
221 | |
222 | |
223 /*------------------------------------------------------------------------ | |
224 * A user was kicked from the GroupChat. | |
225 * | |
226 * @param session The MXit session object | |
227 * @param multimx The MultiMX room object | |
228 * @param nickname The nickname of the user who was kicked | |
229 */ | |
230 static void member_kicked(struct MXitSession* session, struct multimx* multimx, const char* nickname) | |
231 { | |
232 PurpleConversation *convo; | |
233 gboolean isMe = FALSE; | |
234 | |
235 purple_debug_info(MXIT_PLUGIN_ID, "member_kicked: '%s'\n", nickname); | |
236 | |
237 convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, multimx->roomname, session->acc); | |
238 if (convo == NULL) { | |
239 purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); | |
240 return; | |
241 } | |
242 | |
243 /* who was kicked? - compare to our original nickname */ | |
244 if (purple_utf8_strcasecmp(nickname, multimx->nickname) == 0) | |
245 { | |
246 /* you were kicked */ | |
247 purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
248 purple_conv_chat_clear_users(PURPLE_CONV_CHAT(convo)); | |
249 serv_got_chat_left(session->con, multimx->chatid); | |
250 } | |
251 else | |
252 purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, _("was kicked")); | |
212 } | 253 } |
213 | 254 |
214 | 255 |
215 /*------------------------------------------------------------------------ | 256 /*------------------------------------------------------------------------ |
216 * Update the full GroupChat member list. | 257 * Update the full GroupChat member list. |
373 /* Somebody has left */ | 414 /* Somebody has left */ |
374 *ofs = '\0'; | 415 *ofs = '\0'; |
375 member_removed(mx->session, multimx, msg); | 416 member_removed(mx->session, multimx, msg); |
376 mx->processed = TRUE; | 417 mx->processed = TRUE; |
377 } | 418 } |
419 else if ((ofs = strstr(msg, " has been kicked")) != NULL) { | |
420 /* Somebody has been kicked */ | |
421 *ofs = '\0'; | |
422 member_kicked(mx->session, multimx, msg); | |
423 mx->processed = TRUE; | |
424 } | |
378 else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) { | 425 else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) { |
379 member_update(mx->session, multimx, msg + strlen("The following users are in this MultiMx:") + 1); | 426 member_update(mx->session, multimx, msg + strlen("The following users are in this MultiMx:") + 1); |
380 mx->processed = TRUE; | 427 mx->processed = TRUE; |
381 } | 428 } |
382 else { | 429 else { |
580 | 627 |
581 /* Send packet to MXit */ | 628 /* Send packet to MXit */ |
582 mxit_send_message(session, multimx->roomid, message, TRUE, FALSE); | 629 mxit_send_message(session, multimx->roomid, message, TRUE, FALSE); |
583 | 630 |
584 /* Determine our nickname to display */ | 631 /* Determine our nickname to display */ |
585 if (session->profile && (session->profile->nickname[0] != '\0')) /* default is profile name (since that's what everybody else sees) */ | 632 if (multimx->nickname) |
586 nickname = session->profile->nickname; | 633 nickname = multimx->nickname; |
587 else | 634 else |
588 nickname = purple_account_get_alias(purple_connection_get_account(gc)); /* local alias */ | 635 nickname = purple_account_get_alias(purple_connection_get_account(gc)); /* local alias */ |
589 | 636 |
590 /* Display message in chat window */ | 637 /* Display message in chat window */ |
591 serv_got_chat_in(gc, id, nickname, flags, message, time(NULL)); | 638 serv_got_chat_in(gc, id, nickname, flags, message, time(NULL)); |