Mercurial > pidgin
changeset 31488:df716c39f698
Less code duplication.
author | andrew.victor@mxit.com |
---|---|
date | Mon, 21 Mar 2011 21:07:47 +0000 |
parents | cfb5364a0381 |
children | ff2a8a839dbd |
files | libpurple/protocols/mxit/multimx.c |
diffstat | 1 files changed, 22 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/mxit/multimx.c Mon Mar 21 20:52:40 2011 +0000 +++ b/libpurple/protocols/mxit/multimx.c Mon Mar 21 21:07:47 2011 +0000 @@ -177,22 +177,13 @@ /*------------------------------------------------------------------------ * 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 @@ /*------------------------------------------------------------------------ * 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 @@ /*------------------------------------------------------------------------ * 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 @@ /*------------------------------------------------------------------------ * 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 @@ /* 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 {