# HG changeset patch # User andrew.victor@mxit.com # Date 1273595283 0 # Node ID 5139aa9b4077a934039a5233013e78bb2d7f5268 # Parent 40a1111c34d39df1f9cc01a53443b81ff1d2263d 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. diff -r 40a1111c34d3 -r 5139aa9b4077 libpurple/protocols/mxit/multimx.c --- a/libpurple/protocols/mxit/multimx.c Tue May 11 11:40:59 2010 +0000 +++ b/libpurple/protocols/mxit/multimx.c Tue May 11 16:28:03 2010 +0000 @@ -142,6 +142,10 @@ multimx->chatid = groupchatID++; multimx->state = state; + /* determine our nickname (from profile) */ + if (session->profile && (session->profile->nickname[0] != '\0')) + multimx->nickname = g_strdup(session->profile->nickname); + /* Add to GroupChat list */ session->rooms = g_list_append(session->rooms, multimx); @@ -160,6 +164,10 @@ /* Remove from GroupChat list */ session->rooms = g_list_remove(session->rooms, multimx); + /* free nickname */ + if (multimx->nickname) + g_free(multimx->nickname); + /* Deallocate it */ free (multimx); multimx = NULL; @@ -213,6 +221,39 @@ /*------------------------------------------------------------------------ + * A user was kicked from the GroupChat. + * + * @param session The MXit session object + * @param multimx The MultiMX room object + * @param nickname The nickname of the user who was kicked + */ +static void member_kicked(struct MXitSession* session, struct multimx* multimx, const char* nickname) +{ + PurpleConversation *convo; + gboolean isMe = FALSE; + + purple_debug_info(MXIT_PLUGIN_ID, "member_kicked: '%s'\n", nickname); + + convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, multimx->roomname, session->acc); + if (convo == NULL) { + purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname); + return; + } + + /* who was kicked? - compare to our original nickname */ + if (purple_utf8_strcasecmp(nickname, multimx->nickname) == 0) + { + /* you were kicked */ + purple_conv_chat_write(PURPLE_CONV_CHAT(convo), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL)); + purple_conv_chat_clear_users(PURPLE_CONV_CHAT(convo)); + serv_got_chat_left(session->con, multimx->chatid); + } + else + purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, _("was kicked")); +} + + +/*------------------------------------------------------------------------ * Update the full GroupChat member list. * * @param session The MXit session object @@ -375,6 +416,12 @@ member_removed(mx->session, multimx, msg); mx->processed = TRUE; } + else if ((ofs = strstr(msg, " has been kicked")) != NULL) { + /* Somebody has been kicked */ + *ofs = '\0'; + member_kicked(mx->session, multimx, msg); + mx->processed = TRUE; + } else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) { member_update(mx->session, multimx, msg + strlen("The following users are in this MultiMx:") + 1); mx->processed = TRUE; @@ -582,8 +629,8 @@ mxit_send_message(session, multimx->roomid, message, TRUE, FALSE); /* Determine our nickname to display */ - if (session->profile && (session->profile->nickname[0] != '\0')) /* default is profile name (since that's what everybody else sees) */ - nickname = session->profile->nickname; + if (multimx->nickname) + nickname = multimx->nickname; else nickname = purple_account_get_alias(purple_connection_get_account(gc)); /* local alias */ diff -r 40a1111c34d3 -r 5139aa9b4077 libpurple/protocols/mxit/multimx.h --- a/libpurple/protocols/mxit/multimx.h Tue May 11 11:40:59 2010 +0000 +++ b/libpurple/protocols/mxit/multimx.h Tue May 11 16:28:03 2010 +0000 @@ -41,6 +41,7 @@ char roomname[MXIT_CP_MAX_ALIAS_LEN]; /* name of the room */ char roomid[MXIT_CP_MAX_JID_LEN]; /* internal JID for room */ int chatid; /* libpurple chat ID */ + char* nickname; /* our nickname in the room */ short state; /* state */ };