# HG changeset patch # User Matthew Wild # Date 1540991822 0 # Node ID ae0aca2c0ebb11b47ebbb9dbdf7e9e6bc5c01cfa # Parent dcd85bc34d21d29d91a0ff80a525dd591d68d86c# Parent 5a2135964ed31a971847d87e099fb34c22b1b795 Merge 0.11->trunk diff -r dcd85bc34d21 -r ae0aca2c0ebb plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Tue Oct 30 19:18:03 2018 +0100 +++ b/plugins/muc/muc.lib.lua Wed Oct 31 13:17:02 2018 +0000 @@ -1313,20 +1313,31 @@ end end local is_semi_anonymous = self:get_whois() == "moderators"; - for occupant, old_role in pairs(occupants_updated) do - self:publicise_occupant_status(occupant, x, nil, actor, reason); - if occupant.role == nil then - module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); - elseif is_semi_anonymous and - (old_role == "moderator" and occupant.role ~= "moderator") or - (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status - -- Send everyone else's presences (as jid visibility has changed) - for real_jid in occupant:each_session() do - self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 - return occupant.bare_jid ~= jid; - end); + + if next(occupants_updated) ~= nil then + for occupant, old_role in pairs(occupants_updated) do + self:publicise_occupant_status(occupant, x, nil, actor, reason); + if occupant.role == nil then + module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); + elseif is_semi_anonymous and + (old_role == "moderator" and occupant.role ~= "moderator") or + (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status + -- Send everyone else's presences (as jid visibility has changed) + for real_jid in occupant:each_session() do + self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 + return occupant.bare_jid ~= jid; + end); + end end end + else + -- Announce affiliation change for a user that is not currently in the room, + -- XEP-0045 (v1.31.2) example 195 + -- add_item(x, affiliation, role, jid, nick, actor_nick, actor_jid, reason) + local announce_msg = st.message({ from = self.jid }) + :add_child(add_item(st.clone(x), affiliation, nil, jid, nil, nil, nil, reason)); + local min_role = is_semi_anonymous and "moderator" or "none"; + self:broadcast(announce_msg, muc_util.only_with_min_role(min_role)); end self:save(true); diff -r dcd85bc34d21 -r ae0aca2c0ebb plugins/muc/util.lib.lua --- a/plugins/muc/util.lib.lua Tue Oct 30 19:18:03 2018 +0100 +++ b/plugins/muc/util.lib.lua Wed Oct 31 13:17:02 2018 +0000 @@ -55,4 +55,13 @@ return stanza:maptags(muc_x_filter); end +function _M.only_with_min_role(role) + local min_role_value = _M.valid_roles[role]; + return function (nick, occupant) + if _M.valid_roles[occupant.role or "none"] >= min_role_value then + return true; + end + end; +end + return _M; diff -r dcd85bc34d21 -r ae0aca2c0ebb spec/scansion/muc_affiliation_notify.scs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/scansion/muc_affiliation_notify.scs Wed Oct 31 13:17:02 2018 +0000 @@ -0,0 +1,137 @@ +# MUC: Notification of affiliation changes of non-occupants + +[Client] Romeo + jid: user@localhost + password: password + +[Client] Juliet + jid: user2@localhost + password: password + +[Client] Rosaline + jid: user3@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +# Submit config form +Romeo sends: + + + + + http://jabber.org/protocol/muc#roomconfig + + + + + +Romeo receives: + + + +# Promote Juliet to member +Romeo sends: + + + + + + +# Juliet is not in the room, so an affiliation change message is received + +Romeo receives: + + + + + + +# The affiliation change succeeded + +Romeo receives: + + +# Juliet connects, and joins the room +Juliet connects + +Juliet sends: + + + + +Juliet receives: + + +Juliet receives: + + +Juliet receives: + + +Romeo receives: + + +# To check the status of the room is as expected, Romeo requests the member list + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +# Romeo grants membership to Rosaline, who is not in the room + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +Romeo receives: + + +Romeo sends: + + Finished! + + +Juliet receives: + + Finished! +