aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/members_only.lib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/muc/members_only.lib.lua')
-rw-r--r--plugins/muc/members_only.lib.lua33
1 files changed, 30 insertions, 3 deletions
diff --git a/plugins/muc/members_only.lib.lua b/plugins/muc/members_only.lib.lua
index 1e5e6a56..76c4eab6 100644
--- a/plugins/muc/members_only.lib.lua
+++ b/plugins/muc/members_only.lib.lua
@@ -47,6 +47,19 @@ local function set_members_only(room, members_only)
return true;
end
+local function get_allow_member_invites(room)
+ return room._data.allow_member_invites;
+end
+
+-- Allows members to invite new members into a members-only room,
+-- effectively creating an invite-only room
+local function set_allow_member_invites(room, allow_member_invites)
+ allow_member_invites = allow_member_invites and true or nil;
+ if room._data.allow_member_invites == allow_member_invites then return false; end
+ room._data.allow_member_invites = allow_member_invites;
+ return true;
+end
+
module:hook("muc-disco#info", function(event)
event.reply:tag("feature", {var = get_members_only(event.room) and "muc_membersonly" or "muc_open"}):up();
end);
@@ -58,6 +71,12 @@ module:hook("muc-config-form", function(event)
label = "Make Room Members-Only?";
value = get_members_only(event.room);
});
+ table.insert(event.form, {
+ name = "{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites";
+ type = "boolean";
+ label = "Allow members to invite new members?";
+ value = get_allow_member_invites(event.room);
+ });
end, 100-6);
module:hook("muc-config-submitted/muc#roomconfig_membersonly", function(event)
@@ -66,6 +85,12 @@ module:hook("muc-config-submitted/muc#roomconfig_membersonly", function(event)
end
end);
+module:hook("muc-config-submitted/{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites", function(event)
+ if set_allow_member_invites(event.room, event.value) then
+ event.status_codes["104"] = true;
+ end
+end);
+
-- No affiliation => role of "none"
module:hook("muc-get-default-role", function(event)
if not event.affiliation and get_members_only(event.room) then
@@ -96,7 +121,7 @@ module:hook("muc-pre-invite", function(event)
if get_members_only(room) then
local stanza = event.stanza;
local affiliation = room:get_affiliation(stanza.attr.from);
- if valid_affiliations[affiliation or "none"] < valid_affiliations.admin then
+ if not room._data.allow_member_invites and valid_affiliations[affiliation or "none"] < valid_affiliations.admin then
event.origin.send(st.error_reply(stanza, "auth", "forbidden"));
return true;
end
@@ -110,13 +135,13 @@ module:hook("muc-invite", function(event)
local stanza = event.stanza;
local invitee = stanza.attr.to;
local affiliation = room:get_affiliation(invitee);
- if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then
+ if valid_affiliations[affiliation or "none"] <= valid_affiliations.none and room._data.allow_member_invites then
local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user")
:get_child("invite").attr.from;
module:log("debug", "%s invited %s into members only room %s, granting membership",
from, invitee, room.jid);
-- This might fail; ignore for now
- room:set_affiliation(from, invitee, "member", "Invited by " .. from);
+ room:set_affiliation(true, invitee, "member", "Invited by " .. from);
room:save();
end
end
@@ -125,4 +150,6 @@ end);
return {
get = get_members_only;
set = set_members_only;
+ get_allow_member_invites = get_allow_member_invites;
+ set_allow_member_invites = set_allow_member_invites;
};