pidgin.mxit: cd76b2b3: Improve the handling of user's being kic...

andrew.victor at mxit.com andrew.victor at mxit.com
Tue May 11 12:31:34 EDT 2010


-----------------------------------------------------------------
Revision: cd76b2b360d97e137a159f4300452003461468ec
Ancestor: 097880e091f755dd2289d39384e44f8ae4e33589
Author: andrew.victor at mxit.com
Date: 2010-05-11T16:28:03
Branch: im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/cd76b2b360d97e137a159f4300452003461468ec

Modified files:
        libpurple/protocols/mxit/multimx.c
        libpurple/protocols/mxit/multimx.h

ChangeLog: 

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.


-------------- next part --------------
============================================================
--- libpurple/protocols/mxit/multimx.c	06c5c309a3c16e4cb2842983e0b61aedf5560037
+++ libpurple/protocols/mxit/multimx.c	87ecbfa119b3381cc3db986138ffcaa5b3397fa0
@@ -142,6 +142,10 @@ static struct multimx* room_create(struc
 	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 @@ static void room_remove(struct MXitSessi
 	/* 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 @@ static void member_removed(struct MXitSe
 
 
 /*------------------------------------------------------------------------
+ * 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 @@ void multimx_message_received(struct RXM
 			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 @@ int mxit_chat_send(PurpleConnection *gc,
 	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 */
 
============================================================
--- libpurple/protocols/mxit/multimx.h	8eae0405927377edb9e973d32e962b1078149c4a
+++ libpurple/protocols/mxit/multimx.h	1e9244737406ef09dc294df1f87c3019edf3cff2
@@ -41,6 +41,7 @@ struct multimx {
 	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 */
 };
 


More information about the Commits mailing list