From e725335ed389622ebad4b84997e9bd22bd2e6a7b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 21 Feb 2022 11:24:58 +0100 Subject: mod_carbons: Allow plugging into decision of whether to carbon-copy Similar procedure as mod_csi_simple and mod_mam --- plugins/mod_carbons.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_carbons.lua b/plugins/mod_carbons.lua index 5b0bdeb7..7a5b757c 100644 --- a/plugins/mod_carbons.lua +++ b/plugins/mod_carbons.lua @@ -69,6 +69,12 @@ local function should_copy(stanza, c2s, user_bare) --> boolean, reason: string 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 @@ local function message_handler(event, c2s) 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); -- cgit v1.2.3