Software /
code /
prosody
Comparison
plugins/mod_carbons.lua @ 12308:063ce658c181
mod_carbons: Allow plugging into decision of whether to carbon-copy
Similar procedure as mod_csi_simple and mod_mam
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 21 Feb 2022 11:24:58 +0100 |
parent | 12234:1c47162dd965 |
child | 12977:74b9e05af71e |
comparison
equal
deleted
inserted
replaced
12307:dcad3a207915 | 12308:063ce658c181 |
---|---|
67 end | 67 end |
68 | 68 |
69 return false, "default"; | 69 return false, "default"; |
70 end | 70 end |
71 | 71 |
72 module:hook("carbons-should-copy", function (event) | |
73 local should, why = should_copy(event.stanza); | |
74 event.reason = why; | |
75 return should; | |
76 end, -1) | |
77 | |
72 local function message_handler(event, c2s) | 78 local function message_handler(event, c2s) |
73 local origin, stanza = event.origin, event.stanza; | 79 local origin, stanza = event.origin, event.stanza; |
74 local orig_type = stanza.attr.type or "normal"; | 80 local orig_type = stanza.attr.type or "normal"; |
75 local orig_from = stanza.attr.from; | 81 local orig_from = stanza.attr.from; |
76 local bare_from = jid_bare(orig_from); | 82 local bare_from = jid_bare(orig_from); |
99 if not user_sessions then | 105 if not user_sessions then |
100 module:log("debug", "Skip carbons for offline user"); | 106 module:log("debug", "Skip carbons for offline user"); |
101 return -- No use in sending carbons to an offline user | 107 return -- No use in sending carbons to an offline user |
102 end | 108 end |
103 | 109 |
104 local should, why = should_copy(stanza, c2s, bare_jid); | 110 local event_payload = { stanza = stanza; session = origin }; |
111 local should = module:fire_event("carbons-should-copy", event_payload); | |
112 local why = event_payload.reason; | |
105 | 113 |
106 if not should then | 114 if not should then |
107 module:log("debug", "Not copying stanza: %s (%s)", stanza:top_tag(), why); | 115 module:log("debug", "Not copying stanza: %s (%s)", stanza:top_tag(), why); |
108 if why == "private" and not c2s then | 116 if why == "private" and not c2s then |
109 stanza:maptags(function(tag) | 117 stanza:maptags(function(tag) |