Mercurial > pidgin
diff libpurple/protocols/jabber/jabber.c @ 26802:af2b87aa82ee
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.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 03 May 2009 19:53:53 +0000 |
parents | 93bf089e6233 |
children | 1dfa009f6db5 |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Sun May 03 19:36:36 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Sun May 03 19:53:53 2009 +0000 @@ -2590,21 +2590,32 @@ { 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 @@ { 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 @@ 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 |