diff options
author | daurnimator <quae@daurnimator.com> | 2014-10-15 17:08:19 -0400 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2014-10-15 17:08:19 -0400 |
commit | daca47c82e1f5123c05a34d9f377e688dd212382 (patch) | |
tree | 071c9a799fd2d62735e98a99e6523583f6da3eaf | |
parent | d767ec632d58626ebe56cc1b69693cf70bf24ed2 (diff) | |
download | prosody-daca47c82e1f5123c05a34d9f377e688dd212382.tar.gz prosody-daca47c82e1f5123c05a34d9f377e688dd212382.zip |
plugins/muc/muc.lib: Add :each_affiliation() iterator
-rw-r--r-- | plugins/muc/muc.lib.lua | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index bdf67df8..8727a5f2 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -746,10 +746,8 @@ function room_mt:handle_admin_query_get_command(origin, stanza) local affiliation_rank = valid_affiliations[affiliation]; if affiliation_rank >= valid_affiliations.admin and affiliation_rank >= _aff_rank 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 + for jid in self:each_affiliation(_aff or "none") do + reply:tag("item", {affiliation = _aff, jid = jid}):up(); end origin.send(reply:up()); return true; @@ -988,6 +986,21 @@ function room_mt:get_affiliation(jid) return result; end +-- Iterates over jid, affiliation pairs +function room_mt:each_affiliation(with_affiliation) + if not with_affiliation then + return pairs(self._affiliations); + else + return function(_affiliations, jid) + local affiliation; + repeat -- Iterate until we get a match + jid, affiliation = next(_affiliations, jid); + until jid == nil or affiliation == with_affiliation + return jid, affiliation; + end, self._affiliations, nil + end +end + function room_mt:set_affiliation(actor, jid, affiliation, reason) if not actor then return nil, "modify", "not-acceptable"; end; @@ -1012,7 +1025,9 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason) if jid_bare(actor) == jid then -- self change -- need at least one owner local is_last = true; - for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end + for j in self:each_affiliation("owner") do + if j ~= jid then is_last = false; break; end + end if is_last then return nil, "cancel", "conflict"; end |