aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-11-16 11:41:08 +0000
committerMatthew Wild <mwild1@gmail.com>2021-11-16 11:41:08 +0000
commit5fe5458da1ae4525df65e54a26f76fe6503b6351 (patch)
tree155f7516fd974d237d66cb0af12b349e14259e1d /plugins/muc
parent5fa66527d5e2a450dc3d6b0e478f9c4fa190a02c (diff)
downloadprosody-5fe5458da1ae4525df65e54a26f76fe6503b6351.tar.gz
prosody-5fe5458da1ae4525df65e54a26f76fe6503b6351.zip
MUC: Add 'muc-pre-set-affiliation' event, allowing to block change or modify data
Diffstat (limited to 'plugins/muc')
-rw-r--r--plugins/muc/muc.lib.lua30
1 files changed, 20 insertions, 10 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 556363ba..e7ebd65d 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1423,6 +1423,24 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason, data)
end
end
+ local event_data = {
+ room = self;
+ actor = actor;
+ jid = jid;
+ affiliation = affiliation or "none";
+ reason = reason;
+ previous_affiliation = target_affiliation;
+ data = data and data or nil; -- coerce false to nil
+ };
+ if not module:fire_event("muc-pre-set-affiliation", event_data) then
+ local err = event_data.error or { type = "cancel", condition = "not-allowed" };
+ return nil, err.type, err.condition;
+ end
+ if affiliation and not data and event_data.data then
+ -- Allow handlers to add data when none was going to be set
+ data = event_data.data;
+ end
+
-- Set in 'database'
self._affiliations[jid] = affiliation;
if not affiliation or data == false or (data ~= nil and next(data) == nil) then
@@ -1497,16 +1515,8 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason, data)
self:save(true);
- module:fire_event("muc-set-affiliation", {
- room = self;
- actor = actor;
- jid = jid;
- affiliation = affiliation or "none";
- reason = reason;
- previous_affiliation = target_affiliation;
- data = data and data or nil; -- coerce false to nil
- in_room = next(occupants_updated) ~= nil;
- });
+ event_data.in_room = next(occupants_updated) ~= nil;
+ module:fire_event("muc-set-affiliation", event_data);
return true;
end