pidgin: a2a9e1db: jabber: Kick by in-room nick, not JID. ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Feb 17 23:46:41 EST 2010


-----------------------------------------------------------------
Revision: a2a9e1db2545692a99d8d962fd05de135f570cad
Ancestor: 238abbf0d5d46af2e64bfe1898f6a306ef692ea4
Author: darkrain42 at pidgin.im
Date: 2010-02-18T04:39:28
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a2a9e1db2545692a99d8d962fd05de135f570cad

Modified files:
        libpurple/protocols/jabber/chat.c
        libpurple/protocols/jabber/chat.h
        libpurple/protocols/jabber/jabber.c

ChangeLog: 

jabber: Kick by in-room nick, not JID.  Reduces code, but is still in-spec (and seems to be the preferred method)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/chat.c	1b2ee16110281b79806dbec67b5a1fdc45b4c9a6
+++ libpurple/protocols/jabber/chat.c	d3880938cb5c9d5a92e15a710460a139b3008a94
@@ -1048,7 +1048,8 @@ gboolean jabber_chat_affiliation_list(Ja
 	return TRUE;
 }
 
-gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role)
+gboolean jabber_chat_role_user(JabberChat *chat, const char *who,
+                               const char *role, const char *why)
 {
 	char *to;
 	JabberIq *iq;
@@ -1071,6 +1072,10 @@ gboolean jabber_chat_role_user(JabberCha
 	item = xmlnode_new_child(query, "item");
 	xmlnode_set_attrib(item, "nick", jcm->handle);
 	xmlnode_set_attrib(item, "role", role);
+	if (why) {
+		xmlnode *reason = xmlnode_new_child(item, "reason");
+		xmlnode_insert_data(reason, why, -1);
+	}
 
 	jabber_iq_send(iq);
 
@@ -1138,37 +1143,6 @@ gboolean jabber_chat_role_list(JabberCha
 	return TRUE;
 }
 
-gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why)
-{
-	JabberIq *iq;
-	JabberChatMember *jcm = g_hash_table_lookup(chat->members, who);
-	char *to;
-	xmlnode *query, *item, *reason;
-
-	if(!jcm || !jcm->jid)
-		return FALSE;
-
-	iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
-			"http://jabber.org/protocol/muc#admin");
-
-	to = g_strdup_printf("%s@%s", chat->room, chat->server);
-	xmlnode_set_attrib(iq->node, "to", to);
-	g_free(to);
-
-	query = xmlnode_get_child(iq->node, "query");
-	item = xmlnode_new_child(query, "item");
-	xmlnode_set_attrib(item, "jid", jcm->jid);
-	xmlnode_set_attrib(item, "role", "none");
-	if(why) {
-		reason = xmlnode_new_child(item, "reason");
-		xmlnode_insert_data(reason, why, -1);
-	}
-
-	jabber_iq_send(iq);
-
-	return TRUE;
-}
-
 static void jabber_chat_disco_traffic_cb(JabberStream *js, const char *from,
                                          JabberIqType type, const char *id,
                                          xmlnode *packet, gpointer data)
============================================================
--- libpurple/protocols/jabber/chat.h	cbe69a6aac3a5bb37feb2e194260390909ea98ca
+++ libpurple/protocols/jabber/chat.h	cd06d2018bb1f026227bce25deb36221aa518606
@@ -100,7 +100,7 @@ gboolean jabber_chat_role_user(JabberCha
 		const char *affiliation);
 gboolean jabber_chat_affiliation_list(JabberChat *chat, const char *affiliation);
 gboolean jabber_chat_role_user(JabberChat *chat, const char *who,
-		const char *role);
+		const char *role, const char *why);
 gboolean jabber_chat_role_list(JabberChat *chat, const char *role);
 gboolean jabber_chat_kick_user(JabberChat *chat, const char *who,
 		const char *why);
============================================================
--- libpurple/protocols/jabber/jabber.c	73a60715ffd792046a49c901b6f7108512da1b35
+++ libpurple/protocols/jabber/jabber.c	631ee6d017eb2c70d67105efbf00d4e214aaf125
@@ -2721,7 +2721,7 @@ static PurpleCmdRet jabber_cmd_chat_role
 		char **nicks = g_strsplit(args[1], " ", -1);
 
 		for (i = 0; nicks[i]; i++)
-			if (!jabber_chat_role_user(chat, nicks[i], args[0])) {
+			if (!jabber_chat_role_user(chat, nicks[i], args[0], NULL)) {
 				*error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
 										 args[0], nicks[i]);
 				g_strfreev(nicks);
@@ -2779,7 +2779,7 @@ static PurpleCmdRet jabber_cmd_chat_kick
 	if(!chat || !args || !args[0])
 		return PURPLE_CMD_RET_FAILED;
 
-	if(!jabber_chat_kick_user(chat, args[0], args[1])) {
+	if(!jabber_chat_role_user(chat, args[0], "none", args[1])) {
 		*error = g_strdup_printf(_("Unable to kick user %s"), args[0]);
 		return PURPLE_CMD_RET_FAILED;
 	}


More information about the Commits mailing list