pidgin.mxit: 18fa5667: Less code duplication.

andrew.victor at mxit.com andrew.victor at mxit.com
Mon Mar 21 17:31:02 EDT 2011


----------------------------------------------------------------------
Revision: 18fa56675cdd6066f41dd02e736ca759458adbb3
Parent:   cb648f13e19ca0b7edb682842239c3017a2f1fcc
Author:   andrew.victor at mxit.com
Date:     03/21/11 17:07:47
Branch:   im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/18fa56675cdd6066f41dd02e736ca759458adbb3

Changelog: 

Less code duplication.


Changes against parent cb648f13e19ca0b7edb682842239c3017a2f1fcc

  patched  libpurple/protocols/mxit/multimx.c

-------------- next part --------------
============================================================
--- libpurple/protocols/mxit/multimx.c	2385277f739ac1e40e9136019956611fd8b3ac5c
+++ libpurple/protocols/mxit/multimx.c	07e50dbfadf8c0e41bf637c4e3c809d461bbc9fc
@@ -177,22 +177,13 @@ static void room_remove(struct MXitSessi
 /*------------------------------------------------------------------------
  * Another user has join the GroupChat, add them to the member-list.
  *
- *  @param session		The MXit session object
- *  @param multimx		The MultiMX room object
+ *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who joined the room
  */
-static void member_added(struct MXitSession* session, struct multimx* multimx, const char* nickname)
+static void member_added(PurpleConversation* convo, const char* nickname)
 {
-	PurpleConversation *convo;
-
 	purple_debug_info(MXIT_PLUGIN_ID, "member_added: '%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;
-	}
-
 	purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), nickname, NULL, PURPLE_CBFLAGS_NONE, TRUE);
 }
 
@@ -200,45 +191,27 @@ static void member_added(struct MXitSess
 /*------------------------------------------------------------------------
  * Another user has left the GroupChat, remove them from the member-list.
  *
- *  @param session		The MXit session object
- *  @param multimx		The MultiMX room object
+ *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who left the room
  */
-static void member_removed(struct MXitSession* session, struct multimx* multimx, const char* nickname)
+static void member_removed(PurpleConversation* convo, const char* nickname)
 {
-	PurpleConversation *convo;
-
 	purple_debug_info(MXIT_PLUGIN_ID, "member_removed: '%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;
-	}
-
 	purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, NULL);
 }
 
 
 /*------------------------------------------------------------------------
- * A user was kicked from the GroupChat.
+ * A user was kicked from the GroupChat, remove them from the member-list.
  *
- *  @param session		The MXit session object
- *  @param multimx		The MultiMX room object
+ *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who was kicked
  */
-static void member_kicked(struct MXitSession* session, struct multimx* multimx, const char* nickname)
+static void member_kicked(PurpleConversation* convo, const char* nickname)
 {
-	PurpleConversation *convo;
-
 	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;
-	}
-
 	purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nickname, _("was kicked"));
 }
 
@@ -246,21 +219,14 @@ static void member_kicked(struct MXitSes
 /*------------------------------------------------------------------------
  * You were kicked from the GroupChat.
  *
+ *  @param convo		The Conversation object
  *  @param session		The MXit session object
  *  @param multimx		The MultiMX room object
  */
-static void you_kicked(struct MXitSession* session, struct multimx* multimx)
+static void you_kicked(PurpleConversation* convo, struct MXitSession* session, struct multimx* multimx)
 {
-	PurpleConversation *convo;
-
 	purple_debug_info(MXIT_PLUGIN_ID, "you_kicked\n");
 
-	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;
-	}
-
 	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);
@@ -270,24 +236,16 @@ static void you_kicked(struct MXitSessio
 /*------------------------------------------------------------------------
  * Update the full GroupChat member list.
  *
- *  @param session		The MXit session object
- *  @param multimx		The MultiMX room object
+ *  @param convo		The Conversation object
  *  @param data			The nicknames of the users in the room (separated by \n)
  */
-static void member_update(struct MXitSession* session, struct multimx* multimx, char* data)
+static void member_update(PurpleConversation* convo, char* data)
 {
-	PurpleConversation *convo;
 	gchar** userlist;
 	int i = 0;
 
 	purple_debug_info(MXIT_PLUGIN_ID, "member_update: '%s'\n", data);
 
-	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;
-	}
-
 	/* Clear list */
 	purple_conv_chat_clear_users(PURPLE_CONV_CHAT(convo));
 
@@ -417,32 +375,38 @@ void multimx_message_received(struct RXM
 		/* Must be a service message */
 		char* ofs;
 
+		PurpleConversation* convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, multimx->roomname, mx->session->acc);
+		if (convo == NULL) {
+			purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname);
+			return;
+		}
+
 		/* Determine if somebody has joined or left - update member-list */
 		if ((ofs = strstr(msg, " has joined")) != NULL) {
 			/* Somebody has joined */
 			*ofs = '\0';
-			member_added(mx->session, multimx, msg);
+			member_added(convo, msg);
 			mx->processed = TRUE;
 		}
 		else if ((ofs = strstr(msg, " has left")) != NULL) {
 			/* Somebody has left */
 			*ofs = '\0';
-			member_removed(mx->session, multimx, msg);
+			member_removed(convo, 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);
+			member_kicked(convo, msg);
 			mx->processed = TRUE;
 		}
 		else if (strcmp(msg, "You have been kicked.") == 0) {
 			/* You have been kicked */
-			you_kicked(mx->session, multimx);
+			you_kicked(convo, mx->session, multimx);
 			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);
+			member_update(convo, msg + strlen("The following users are in this MultiMx:") + 1);
 			mx->processed = TRUE;
 		}
 		else {


More information about the Commits mailing list