aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/muc.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-05 14:49:06 +0100
committerKim Alvefur <zash@zash.se>2021-12-05 14:49:06 +0100
commit2807299fba66bf468dd5c534c63081f9b6ac4ce2 (patch)
tree57cc1819335d2db374ff1c543f9452797202f217 /plugins/muc/muc.lib.lua
parentd48fa1de17cf1435ae733053b8e65e295f2b622f (diff)
downloadprosody-2807299fba66bf468dd5c534c63081f9b6ac4ce2.tar.gz
prosody-2807299fba66bf468dd5c534c63081f9b6ac4ce2.zip
MUC: Allow modules a chance to act prior to room destruction
Diffstat (limited to 'plugins/muc/muc.lib.lua')
-rw-r--r--plugins/muc/muc.lib.lua16
1 files changed, 12 insertions, 4 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 01704a36..c65ff9c7 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1018,8 +1018,12 @@ function room_mt:clear(x)
end
function room_mt:destroy(newjid, reason, password)
- local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})
- :tag("destroy", {jid=newjid});
+ local x = st.stanza("x", { xmlns = "http://jabber.org/protocol/muc#user" });
+ local event = { room = self; newjid = newjid; reason = reason; password = password; x = x, allowed = true };
+ module:fire_event("muc-pre-room-destroy", event);
+ if not event.allowed then return false, event.error; end
+ newjid, reason, password = event.newjid, event.reason, event.password;
+ x:tag("destroy", { jid = newjid });
if reason then x:tag("reason"):text(reason):up(); end
if password then x:tag("password"):text(password):up(); end
x:up();
@@ -1172,8 +1176,12 @@ function room_mt:handle_owner_query_set_to_room(origin, stanza)
local newjid = child.attr.jid;
local reason = child:get_child_text("reason");
local password = child:get_child_text("password");
- self:destroy(newjid, reason, password);
- origin.send(st.reply(stanza));
+ local destroyed, err = self:destroy(newjid, reason, password);
+ if destroyed then
+ origin.send(st.reply(stanza));
+ else
+ origin.send(st.error_reply(stanza, err or "cancel", "not-allowed"));
+ end
return true;
elseif child.name == "x" and child.attr.xmlns == "jabber:x:data" then
return self:process_form(origin, stanza);