Software /
code /
prosody
Diff
plugins/muc/muc.lib.lua @ 1744:265863a5612b
MUC: Added support for requesting various lists (owner, admin, voice, etc).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 07 Sep 2009 20:33:24 +0500 |
parent | 1743:d00b144f4bcf |
child | 1745:15039fac3693 |
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua Mon Sep 07 20:31:35 2009 +0500 +++ b/plugins/muc/muc.lib.lua Mon Sep 07 20:33:24 2009 +0500 @@ -318,24 +318,57 @@ else origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end - elseif stanza.name == "iq" and type == "set" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then + elseif stanza.name == "iq" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then local actor = stanza.attr.from; local affiliation = self:get_affiliation(actor); local current_nick = self._jid_nick[actor]; local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); - local item = stanza.tags[1].tags[1]; + local item = stanza.tags[1] and stanza.tags[1].tags[1]; if item and item.name == "item" then - local callback = function() origin.send(st.reply(stanza)); end - if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then - local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); - if not success then origin.send(st.error_reply(stanza, errtype, err)); end - elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then - local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); - if not success then origin.send(st.error_reply(stanza, errtype, err)); end - else - origin.send(st.error_reply(stanza, "cancel", "bad-request")); + if type == "set" then + local callback = function() origin.send(st.reply(stanza)); end + if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then + local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); + if not success then origin.send(st.error_reply(stanza, errtype, err)); end + elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then + local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); + if not success then origin.send(st.error_reply(stanza, errtype, err)); end + else + origin.send(st.error_reply(stanza, "cancel", "bad-request")); + end + elseif type == "get" then + local _aff = item.attr.affiliation; + local _rol = item.attr.role; + if _aff and not _rol then + if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then + local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); + for jid, affiliation in pairs(self._affiliations) do + if affiliation == _aff then + reply:tag("item", {affiliation = _aff, jid = jid}):up(); + end + end + origin.send(reply); + else + origin.send(st.error_reply(stanza, "auth", "forbidden")); + end + elseif _rol and not _aff then + if role == "moderator" then -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? + if _rol == "none" then _rol = nil; end + local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); + for nick, occupant in pairs(self._occupants) do + if occupant.role == _rol then + reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); + end + end + origin.send(reply); + else + origin.send(st.error_reply(stanza, "auth", "forbidden")); + end + else + origin.send(st.error_reply(stanza, "cancel", "bad-request")); + end end - else + elseif type == "set" or type == "get" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); end elseif stanza.name == "message" and type == "groupchat" then @@ -410,7 +443,7 @@ local role = self:get_default_role(affiliation); local p = st.presence({type = "unavailable"}) :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) - :tag("item", {affiliation=affiliation, role=role or "none"}):up(); + :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up(); local x = p.tags[1]; local item = x.tags[1]; if not role then -- getting kicked @@ -457,7 +490,7 @@ if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end local p = st.presence({from = nick, type = "unavailable"}) :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) - :tag("item", {affiliation=occupant.affiliation, nick=nick, role=role or "none"}):up(); + :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}):up(); if not role then -- kick self._occupants[nick] = nil; for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick