# HG changeset patch # User Paul Aurich # Date 1246838156 0 # Node ID c4196cd47602b519ac9e1ef859b3ae244360e5fe # Parent 1a563a740c7fbf101ac55ec61abf2bb76ae6c6fd Add support for XEP-0045 code 307 (a.k.a. kicks). diff -r 1a563a740c7f -r c4196cd47602 ChangeLog --- a/ChangeLog Sun Jul 05 22:59:43 2009 +0000 +++ b/ChangeLog Sun Jul 05 23:55:56 2009 +0000 @@ -81,6 +81,8 @@ * Google Talk mail notifications should now work for people for whom they inexplicably did not. (Thanks to yukam for determining the reason) * New XMPP and Google Talk accounts require SSL by default. + * Display kicks (and the reasons given) in chat rooms when an occupant is + kicked. Yahoo: * P2P file transfers. (Sulabh Mahajan) diff -r 1a563a740c7f -r c4196cd47602 libpurple/protocols/jabber/presence.c --- a/libpurple/protocols/jabber/presence.c Sun Jul 05 22:59:43 2009 +0000 +++ b/libpurple/protocols/jabber/presence.c Sun Jul 05 23:55:56 2009 +0000 @@ -690,6 +690,8 @@ if(type && !strcmp(type, "unavailable")) { gboolean nick_change = FALSE; + gboolean kick = FALSE; + gboolean is_our_resource = FALSE; /* Is the presence about us? */ /* If the chat nick is invalid, we haven't yet joined, or we've * already left (it was probably us leaving after we closed the @@ -706,6 +708,8 @@ return; } + is_our_resource = (0 == g_utf8_collate(jid->resource, chat->handle)); + jabber_buddy_remove_resource(jb, jid->resource); if(chat->muc) { xmlnode *x; @@ -719,10 +723,13 @@ continue; if(!(code = xmlnode_get_attrib(stat, "code"))) continue; + + item = xmlnode_get_child(x, "item"); + if(!strcmp(code, "301")) { /* XXX: we got banned */ } else if(!strcmp(code, "303")) { - if(!(item = xmlnode_get_child(x, "item"))) + if (!item) continue; if(!(nick = xmlnode_get_attrib(item, "nick"))) continue; @@ -735,7 +742,46 @@ jabber_chat_remove_handle(chat, jid->resource); break; } else if(!strcmp(code, "307")) { - /* XXX: we got kicked */ + /* Someone was kicked from the room */ + xmlnode *reason = NULL, *actor = NULL; + const char *actor_name = NULL; + char *reason_text = NULL; + char *tmp; + + kick = TRUE; + + if (item) { + reason = xmlnode_get_child(item, "reason"); + actor = xmlnode_get_child(item, "actor"); + + if (reason != NULL) + reason_text = xmlnode_get_data(reason); + if (actor != NULL) + actor_name = xmlnode_get_attrib(actor, "jid"); + } + + if (reason_text == NULL) + reason_text = g_strdup(_("No reason")); + + if (is_our_resource) { + if (actor_name != NULL) + tmp = g_strdup_printf(_("You have been kicked by %s: (%s)"), + actor_name, reason_text); + else + tmp = g_strdup_printf(_("You have been kicked: (%s)"), + reason_text); + } else { + if (actor_name != NULL) + tmp = g_strdup_printf(_("Kicked by %s (%s)"), + actor_name, reason_text); + else + tmp = g_strdup_printf(_("Kicked (%s)"), + reason_text); + } + + g_free(reason_text); + g_free(status); + status = tmp; } else if(!strcmp(code, "321")) { /* XXX: removed due to an affiliation change */ } else if(!strcmp(code, "322")) { @@ -746,7 +792,11 @@ } } if(!nick_change) { - if(!g_utf8_collate(jid->resource, chat->handle)) { + if (is_our_resource) { + if (kick) + purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), jid->resource, + status, PURPLE_MESSAGE_SYSTEM, time(NULL)); + serv_got_chat_left(js->gc, chat->id); jabber_chat_destroy(chat); } else {