aboutsummaryrefslogtreecommitdiffstats
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
commit6e323b0ff24141fd6b28ba78fec2995fe1411272 (patch)
tree89590cb4d1ed9ba41260e390d13e0cff6e777b13
parent6171df1e1c3d9b85dc5662e9fb2fc580a96c7320 (diff)
downloadprosody-6e323b0ff24141fd6b28ba78fec2995fe1411272.tar.gz
prosody-6e323b0ff24141fd6b28ba78fec2995fe1411272.zip
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
-rw-r--r--plugins/muc/members_only.lib.lua33
-rw-r--r--plugins/muc/mod_muc.lua2
-rw-r--r--util/async.lua4
3 files changed, 34 insertions, 5 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;
diff --git a/util/async.lua b/util/async.lua
index 0d19af6e..4d9f159f 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -148,7 +148,7 @@ end
function runner_mt:run(input)
if input ~= nil then
table.insert(self.queue, input);
- self:log("debug", "queued new work item, %d items queued", #self.queue);
+ --self:log("debug", "queued new work item, %d items queued", #self.queue);
end
if self.state ~= "ready" then
-- The runner is busy. Indicate that the task item has been
@@ -167,7 +167,7 @@ function runner_mt:run(input)
-- Process task item(s) while the queue is not empty, and we're not blocked
local n, state, err = #q, self.state, nil;
self.state = "running";
- self:log("debug", "running main loop");
+ --self:log("debug", "running main loop");
while n > 0 and state == "ready" and not err do
local consumed;
-- Loop through queue items, and attempt to run them