aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-07-06 15:33:46 +0100
committerMatthew Wild <mwild1@gmail.com>2018-07-06 15:33:46 +0100
commit49677384f67b36e3a302b86151218ee10552cdaa (patch)
tree89590cb4d1ed9ba41260e390d13e0cff6e777b13 /plugins/muc
parent4e35f8575f31db1e39e96a4ea38679a8c42a3f35 (diff)
downloadprosody-49677384f67b36e3a302b86151218ee10552cdaa.tar.gz
prosody-49677384f67b36e3a302b86151218ee10552cdaa.zip
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Diffstat (limited to 'plugins/muc')
-rw-r--r--plugins/muc/members_only.lib.lua33
-rw-r--r--plugins/muc/mod_muc.lua2
2 files changed, 32 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;
};
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index c3975282..d2a5f8de 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -53,6 +53,8 @@ room_mt.set_password = password.set;
local members_only = module:require "muc/members_only";
room_mt.get_members_only = members_only.get;
room_mt.set_members_only = members_only.set;
+room_mt.get_allow_member_invites = members_only.get_allow_member_invites;
+room_mt.set_allow_member_invites = members_only.set_allow_member_invites;
local moderated = module:require "muc/moderated";
room_mt.get_moderated = moderated.get;