mod_carbons: Allow plugging into decision of whether to carbon-copy
Similar procedure as mod_csi_simple and mod_mam
--- a/plugins/mod_carbons.lua Sat Dec 11 18:01:04 2021 +0100
+++ b/plugins/mod_carbons.lua Mon Feb 21 11:24:58 2022 +0100
@@ -69,6 +69,12 @@
return false, "default";
end
+module:hook("carbons-should-copy", function (event)
+ local should, why = should_copy(event.stanza);
+ event.reason = why;
+ return should;
+end, -1)
+
local function message_handler(event, c2s)
local origin, stanza = event.origin, event.stanza;
local orig_type = stanza.attr.type or "normal";
@@ -101,7 +107,9 @@
return -- No use in sending carbons to an offline user
end
- local should, why = should_copy(stanza, c2s, bare_jid);
+ local event_payload = { stanza = stanza; session = origin };
+ local should = module:fire_event("carbons-should-copy", event_payload);
+ local why = event_payload.reason;
if not should then
module:log("debug", "Not copying stanza: %s (%s)", stanza:top_tag(), why);