Mercurial > pidgin.yaz
changeset 13237:b0d020a66144
[gaim-migrate @ 15603]
SF patch 1411796 by Andrej Krivul????k
It adds a /role command to jabber chat rooms.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Sun, 12 Feb 2006 04:35:35 +0000 |
parents | 0fa8153beebf |
children | 1e855032d7bc |
files | COPYRIGHT src/protocols/jabber/chat.c src/protocols/jabber/chat.h src/protocols/jabber/jabber.c |
diffstat | 4 files changed, 79 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Sun Feb 12 04:22:16 2006 +0000 +++ b/COPYRIGHT Sun Feb 12 04:35:35 2006 +0000 @@ -136,6 +136,7 @@ Akuke Kok Cole Kowalski Gary Kramlich +Andrej Krivulčík Patrik Kullman Tuomas Kuosmanen Tero Kuusela
--- a/src/protocols/jabber/chat.c Sun Feb 12 04:22:16 2006 +0000 +++ b/src/protocols/jabber/chat.c Sun Feb 12 04:35:35 2006 +0000 @@ -856,10 +856,12 @@ gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation) { + char *to; JabberIq *iq; - JabberChatMember *jcm = g_hash_table_lookup(chat->members, who); - char *to; xmlnode *query, *item; + JabberChatMember *jcm; + + jcm = g_hash_table_lookup(chat->members, who); if (!jcm || !jcm->jid) return FALSE; @@ -881,6 +883,35 @@ return TRUE; } +gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role) +{ + char *to; + JabberIq *iq; + xmlnode *query, *item; + JabberChatMember *jcm; + + jcm = g_hash_table_lookup(chat->members, who); + + if (!jcm || !jcm->handle) + 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, "nick", jcm->handle); + xmlnode_set_attrib(item, "role", role); + + jabber_iq_send(iq); + + return TRUE; +} + gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why) { JabberIq *iq;
--- a/src/protocols/jabber/chat.h Sun Feb 12 04:22:16 2006 +0000 +++ b/src/protocols/jabber/chat.h Sun Feb 12 04:35:35 2006 +0000 @@ -79,6 +79,8 @@ const char *why); gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation); +gboolean jabber_chat_role_user(JabberChat *chat, const char *who, + const char *role); gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why);
--- a/src/protocols/jabber/jabber.c Sun Feb 12 04:22:16 2006 +0000 +++ b/src/protocols/jabber/jabber.c Sun Feb 12 04:35:35 2006 +0000 @@ -1603,13 +1603,11 @@ if (!args || !args[0] || !args[1]) return GAIM_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 - ) { + 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]); return GAIM_CMD_RET_FAILED; } @@ -1622,6 +1620,33 @@ return GAIM_CMD_RET_OK; } +static GaimCmdRet jabber_cmd_chat_role(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + JabberChat *chat; + + if (!args || !args[0] || !args[1]) + return GAIM_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]); + return GAIM_CMD_RET_FAILED; + } + + chat = jabber_chat_find_by_conv(conv); + + 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 GAIM_CMD_RET_FAILED; + } + + return GAIM_CMD_RET_OK; +} + static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) { @@ -1731,11 +1756,17 @@ _("ban <user> [room]: Ban a user from the room."), NULL); gaim_cmd_register("affiliate", "ws", GAIM_CMD_P_PRPL, - GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | - GAIM_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."), - NULL); + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | + GAIM_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."), + NULL); + gaim_cmd_register("role", "ws", GAIM_CMD_P_PRPL, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | + GAIM_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."), + NULL); gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",