Comparison

plugins/mod_mam/mod_mam.lua @ 12306:81fc7fc77e68

mod_mam: Allow plugging into archive decision Similar procedure as mod_csi_simple
author Kim Alvefur <zash@zash.se>
date Fri, 10 Dec 2021 22:37:32 +0100
parent 12234:1c47162dd965
child 12307:dcad3a207915
comparison
equal deleted inserted replaced
12305:f8b8061461e3 12306:81fc7fc77e68
309 end); 309 end);
310 end 310 end
311 return stanza; 311 return stanza;
312 end 312 end
313 313
314 local function should_store(stanza, c2s) --> boolean, reason: string 314 local function should_store(stanza) --> boolean, reason: string
315 local st_type = stanza.attr.type or "normal"; 315 local st_type = stanza.attr.type or "normal";
316 -- FIXME pass direction of stanza and use that along with bare/full JID addressing 316 -- FIXME pass direction of stanza and use that along with bare/full JID addressing
317 -- for more accurate MUC / type=groupchat check 317 -- for more accurate MUC / type=groupchat check
318 318
319 if st_type == "headline" then 319 if st_type == "headline" then
320 -- Headline messages are ephemeral by definition 320 -- Headline messages are ephemeral by definition
321 return false, "headline"; 321 return false, "headline";
322 end 322 end
323 if st_type == "error" and not c2s then 323 if st_type == "error" then
324 -- Errors not sent sent from a local client 324 -- Errors not sent sent from a local client
325 -- Why would a client send an error anyway? 325 -- Why would a client send an error anyway?
326 if jid_resource(stanza.attr.to) then 326 if jid_resource(stanza.attr.to) then
327 -- Store delivery failure notifications so you know if your own messages 327 -- Store delivery failure notifications so you know if your own messages
328 -- were not delivered. 328 -- were not delivered.
378 -- The IM-NG thing to do here would be to return `not st_to_full` 378 -- The IM-NG thing to do here would be to return `not st_to_full`
379 -- One day ... 379 -- One day ...
380 return false, "default"; 380 return false, "default";
381 end 381 end
382 382
383 module:hook("archive-should-store", function (event)
384 local should, why = should_store(event.stanza);
385 event.reason = why;
386 return should;
387 end, -1)
388
383 -- Handle messages 389 -- Handle messages
384 local function message_handler(event, c2s) 390 local function message_handler(event, c2s)
385 local origin, stanza = event.origin, event.stanza; 391 local origin, stanza = event.origin, event.stanza;
386 local log = c2s and origin.log or module._log; 392 local log = c2s and origin.log or module._log;
387 local orig_from = stanza.attr.from; 393 local orig_from = stanza.attr.from;
394 local with = jid_bare(c2s and orig_to or orig_from); 400 local with = jid_bare(c2s and orig_to or orig_from);
395 401
396 -- Filter out <stanza-id> that claim to be from us 402 -- Filter out <stanza-id> that claim to be from us
397 event.stanza = strip_stanza_id(stanza, store_user); 403 event.stanza = strip_stanza_id(stanza, store_user);
398 404
399 local should, why = should_store(stanza, c2s); 405 local event_payload = { stanza = stanza; session = origin };
406 local should = module:fire_event("archive-should-store", event_payload);
407 local why = event_payload.reason;
408
400 if not should then 409 if not should then
401 log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), why); 410 log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), event_payload.reason);
402 return; 411 return;
403 end 412 end
404 413
405 local clone_for_storage; 414 local clone_for_storage;
406 if not strip_tags:empty() then 415 if not strip_tags:empty() then