Comparison

plugins/muc/members_only.lib.lua @ 6477:29f979f554d3

plugins/muc/members_only: Kick non-members when members-only is turned on
author daurnimator <quae@daurnimator.com>
date Wed, 15 Oct 2014 17:07:16 -0400
parent 6329:6b3eb1611587
child 6991:84e01dbb739e
comparison
equal deleted inserted replaced
6476:fb8a9873728b 6477:29f979f554d3
18 18
19 local function set_members_only(room, members_only) 19 local function set_members_only(room, members_only)
20 members_only = members_only and true or nil; 20 members_only = members_only and true or nil;
21 if room._data.members_only == members_only then return false; end 21 if room._data.members_only == members_only then return false; end
22 room._data.members_only = members_only; 22 room._data.members_only = members_only;
23 if members_only then
24 --[[
25 If as a result of a change in the room configuration the room type is
26 changed to members-only but there are non-members in the room,
27 the service MUST remove any non-members from the room and include a
28 status code of 322 in the presence unavailable stanzas sent to those users
29 as well as any remaining occupants.
30 ]]
31 local occupants_changed = {};
32 for nick, occupant in room:each_occupant() do
33 local affiliation = room:get_affiliation(occupant.bare_jid);
34 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then
35 occupant.role = nil;
36 room:save_occupant(occupant);
37 occupants_changed[occupant] = true;
38 end
39 end
40 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})
41 :tag("status", {code="322"}):up();
42 for occupant in pairs(occupants_changed) do
43 room:publicise_occupant_status(occupant, x);
44 module:fire_event("muc-occupant-left", {room = room; nick = occupant.nick; occupant = occupant;});
45 end
46 end
23 if room.save then room:save(true); end 47 if room.save then room:save(true); end
24 return true; 48 return true;
25 end 49 end
26 50
27 module:hook("muc-disco#info", function(event) 51 module:hook("muc-disco#info", function(event)