pidgin: b3703f59: Add ability to list roles/affiliations i..
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sun May 3 16:20:35 EDT 2009
-----------------------------------------------------------------
Revision: b3703f5983a0cc2409d0c9af899feaef255fe973
Ancestor: eb2138cc8c562bba3cf0071ea33e2e7ab4d636aa
Author: darkrain42 at pidgin.im
Date: 2009-05-03T19:53:53
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b3703f5983a0cc2409d0c9af899feaef255fe973
Modified files:
ChangeLog libpurple/protocols/jabber/chat.c
libpurple/protocols/jabber/chat.h
libpurple/protocols/jabber/jabber.c
ChangeLog:
Add ability to list roles/affiliations in a chat via slash-commands and
modify roles/affiliations of multiple users at a time. Closes #5649.
Slightly modified patch from Andrei Mozzhuhin. The multiple-user support
is inefficient; all the changes can go in one stanza. We should also
actually track roles/affiliations of members since ejabberd's MUC won't
respond to the list query for a non-admin.
-------------- next part --------------
============================================================
--- ChangeLog 43cdde9e1dd30b1fac9dce0a6026c545b90dcb3e
+++ ChangeLog 0847e0e7ff4926dbd7a86831ff7c92404025d726
@@ -31,6 +31,8 @@ version 2.6.0 (??/??/2009):
* Support most recent version of User Avatar. (XEP-0084 v1.1)
* Updated Entity Capabilities support. (Tobias Markmann)
* Better support for receiving remote users' nicknames.
+ * /affiliate and /role will now list the room members with the specified
+ affiliation/role if possible. (Andrei Mozzhuhin)
Yahoo:
* P2P file transfers. (Sulabh Mahajan)
============================================================
--- libpurple/protocols/jabber/chat.c b3a7e0a6655f61e1756f0b1addec638d166b1cf4
+++ libpurple/protocols/jabber/chat.c 366bf5c22ad7d35fc6296a5833d80365fcb85b74
@@ -916,6 +916,68 @@ gboolean jabber_chat_affiliate_user(Jabb
return TRUE;
}
+static void
+jabber_chat_affiliation_list_cb(JabberStream *js, const char *from,
+ JabberIqType type, const char *id,
+ xmlnode *packet, gpointer data)
+{
+ JabberChat *chat;
+ xmlnode *query, *item;
+ int chat_id = GPOINTER_TO_INT(data);
+ GString *buf;
+
+ if(!(chat = jabber_chat_find_by_id(js, chat_id)))
+ return;
+
+ if (type == JABBER_IQ_ERROR)
+ return;
+
+ if(!(query = xmlnode_get_child(packet, "query")))
+ return;
+
+ buf = g_string_new(_("Affiliations:"));
+
+ item = xmlnode_get_child(query, "item");
+ if (item) {
+ for( ; item; item = xmlnode_get_next_twin(item)) {
+ const char *jid = xmlnode_get_attrib(item, "jid");
+ const char *affiliation = xmlnode_get_attrib(item, "affiliation");
+ if (jid && affiliation)
+ g_string_append_printf(buf, "\n%s %s", jid, affiliation);
+ }
+ } else {
+ buf = g_string_append_c(buf, '\n');
+ buf = g_string_append_len(buf, _("No users found"), -1);
+ }
+
+ purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str,
+ PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
+
+ g_string_free(buf, TRUE);
+}
+
+gboolean jabber_chat_affiliation_list(JabberChat *chat, const char *affiliation)
+{
+ JabberIq *iq;
+ char *room_jid;
+ xmlnode *query, *item;
+
+ iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET,
+ "http://jabber.org/protocol/muc#admin");
+
+ room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
+ xmlnode_set_attrib(iq->node, "to", room_jid);
+
+ query = xmlnode_get_child(iq->node, "query");
+ item = xmlnode_new_child(query, "item");
+ xmlnode_set_attrib(item, "affiliation", affiliation);
+
+ jabber_iq_set_callback(iq, jabber_chat_affiliation_list_cb, GINT_TO_POINTER(chat->id));
+ jabber_iq_send(iq);
+
+ return TRUE;
+}
+
gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role)
{
char *to;
@@ -945,6 +1007,67 @@ gboolean jabber_chat_role_user(JabberCha
return TRUE;
}
+static void jabber_chat_role_list_cb(JabberStream *js, const char *from,
+ JabberIqType type, const char *id,
+ xmlnode *packet, gpointer data)
+{
+ JabberChat *chat;
+ xmlnode *query, *item;
+ int chat_id = GPOINTER_TO_INT(data);
+ GString *buf;
+
+ if(!(chat = jabber_chat_find_by_id(js, chat_id)))
+ return;
+
+ if (type == JABBER_IQ_ERROR)
+ return;
+
+ if(!(query = xmlnode_get_child(packet, "query")))
+ return;
+
+ buf = g_string_new(_("Roles:"));
+
+ item = xmlnode_get_child(query, "item");
+ if (item) {
+ for( ; item; item = xmlnode_get_next_twin(item)) {
+ const char *jid = xmlnode_get_attrib(item, "jid");
+ const char *role = xmlnode_get_attrib(item, "role");
+ if (jid && role)
+ g_string_append_printf(buf, "\n%s %s", jid, role);
+ }
+ } else {
+ buf = g_string_append_c(buf, '\n');
+ buf = g_string_append_len(buf, _("No users found"), -1);
+ }
+
+ purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str,
+ PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
+
+ g_string_free(buf, TRUE);
+}
+
+gboolean jabber_chat_role_list(JabberChat *chat, const char *role)
+{
+ JabberIq *iq;
+ char *room_jid;
+ xmlnode *query, *item;
+
+ iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET,
+ "http://jabber.org/protocol/muc#admin");
+
+ room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
+ xmlnode_set_attrib(iq->node, "to", room_jid);
+
+ query = xmlnode_get_child(iq->node, "query");
+ item = xmlnode_new_child(query, "item");
+ xmlnode_set_attrib(item, "role", role);
+
+ jabber_iq_set_callback(iq, jabber_chat_role_list_cb, GINT_TO_POINTER(chat->id));
+ jabber_iq_send(iq);
+
+ return TRUE;
+}
+
gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why)
{
JabberIq *iq;
============================================================
--- libpurple/protocols/jabber/chat.h 64957c6fb9b83298ecc5c07378e6821c3c8d209e
+++ libpurple/protocols/jabber/chat.h 1b58e910562b02a48d253ba6857a9acfa9670b64
@@ -81,8 +81,10 @@ gboolean jabber_chat_affiliate_user(Jabb
const char *why);
gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who,
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);
+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 7ba3d9add3d6891dcc30abd8006991ec0f8823be
+++ libpurple/protocols/jabber/jabber.c ec7aa5f556b98a3c5ff5178f5ff525138859639c
@@ -2590,21 +2590,32 @@ static PurpleCmdRet jabber_cmd_chat_affi
{
JabberChat *chat = jabber_chat_find_by_conv(conv);
- if (!chat || !args || !args[0] || !args[1])
+ if (!chat || !args || !args[0])
return PURPLE_CMD_RET_FAILED;
- if (strcmp(args[1], "owner") != 0 &&
- strcmp(args[1], "admin") != 0 &&
- strcmp(args[1], "member") != 0 &&
- strcmp(args[1], "outcast") != 0 &&
- strcmp(args[1], "none") != 0) {
- *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]);
+ if (strcmp(args[0], "owner") != 0 &&
+ strcmp(args[0], "admin") != 0 &&
+ strcmp(args[0], "member") != 0 &&
+ strcmp(args[0], "outcast") != 0 &&
+ strcmp(args[0], "none") != 0) {
+ *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[0]);
return PURPLE_CMD_RET_FAILED;
}
- if (!jabber_chat_affiliate_user(chat, args[0], args[1])) {
- *error = g_strdup_printf(_("Unable to affiliate user %s as \"%s\""), args[0], args[1]);
- return PURPLE_CMD_RET_FAILED;
+ if (args[1]) {
+ int i;
+ char **nicks = g_strsplit(args[1], " ", -1);
+
+ for (i = 0; nicks[i]; ++i)
+ if (!jabber_chat_affiliate_user(chat, nicks[i], args[0])) {
+ *error = g_strdup_printf(_("Unable to affiliate user %s as \"%s\""), nicks[i], args[0]);
+ g_strfreev(nicks);
+ return PURPLE_CMD_RET_FAILED;
+ }
+
+ g_strfreev(nicks);
+ } else {
+ jabber_chat_affiliation_list(chat, args[0]);
}
return PURPLE_CMD_RET_OK;
@@ -2615,23 +2626,32 @@ static PurpleCmdRet jabber_cmd_chat_role
{
JabberChat *chat = jabber_chat_find_by_conv(conv);
- if (!chat || !args || !args[0] || !args[1])
+ if (!chat || !args || !args[0])
return PURPLE_CMD_RET_FAILED;
- if (strcmp(args[1], "moderator") != 0 &&
- strcmp(args[1], "participant") != 0 &&
- strcmp(args[1], "visitor") != 0 &&
- strcmp(args[1], "none") != 0) {
- *error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]);
+ if (strcmp(args[0], "moderator") != 0 &&
+ strcmp(args[0], "participant") != 0 &&
+ strcmp(args[0], "visitor") != 0 &&
+ strcmp(args[0], "none") != 0) {
+ *error = g_strdup_printf(_("Unknown role: \"%s\""), args[0]);
return PURPLE_CMD_RET_FAILED;
}
- if (!jabber_chat_role_user(chat, args[0], args[1])) {
- *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
- args[1], args[0]);
- return PURPLE_CMD_RET_FAILED;
+ if (args[1]) {
+ int i;
+ char **nicks = g_strsplit(args[1], " ", -1);
+
+ for (i = 0; nicks[i]; i++)
+ if (!jabber_chat_role_user(chat, nicks[i], args[0])) {
+ *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
+ args[0], nicks[i]);
+ return PURPLE_CMD_RET_FAILED;
+ }
+
+ g_strfreev(nicks);
+ } else {
+ jabber_chat_role_list(chat, args[0]);
}
-
return PURPLE_CMD_RET_OK;
}
@@ -3178,13 +3198,13 @@ void jabber_register_commands(void)
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
jabber_cmd_chat_affiliate,
- _("affiliate <user> <owner|admin|member|outcast|none>: Set a user's affiliation with the room."),
+ _("affiliate <owner|admin|member|outcast|none> [nick1] [nick2] ...: Get the users with an affiliation or set users' affiliation with the room."),
NULL);
purple_cmd_register("role", "ws", PURPLE_CMD_P_PRPL,
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
jabber_cmd_chat_role,
- _("role <user> <moderator|participant|visitor|none>: Set a user's role in the room."),
+ _("role <moderator|participant|visitor|none> [nick1] [nick2] ...: Get the users with an role or set users' role with the room."),
NULL);
purple_cmd_register("invite", "ws", PURPLE_CMD_P_PRPL,
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
More information about the Commits
mailing list