comparison mod_smacks/mod_smacks.lua @ 4189:22e7b3d6fcae

mod_smacks: don't store mam results in offline store
author tmolitor <thilo@eightysoft.de>
date Mon, 12 Oct 2020 17:56:10 +0200
parents 362997ededb1
children 0b9501f82e63
comparison
equal deleted inserted replaced
4188:4611999fd8d3 4189:22e7b3d6fcae
24 local tonumber, tostring = tonumber, tostring; 24 local tonumber, tostring = tonumber, tostring;
25 local add_filter = require "util.filters".add_filter; 25 local add_filter = require "util.filters".add_filter;
26 local timer = require "util.timer"; 26 local timer = require "util.timer";
27 local datetime = require "util.datetime"; 27 local datetime = require "util.datetime";
28 28
29 local xmlns_mam2 = "urn:xmpp:mam:2";
29 local xmlns_sm2 = "urn:xmpp:sm:2"; 30 local xmlns_sm2 = "urn:xmpp:sm:2";
30 local xmlns_sm3 = "urn:xmpp:sm:3"; 31 local xmlns_sm3 = "urn:xmpp:sm:3";
31 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; 32 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas";
32 local xmlns_delay = "urn:xmpp:delay"; 33 local xmlns_delay = "urn:xmpp:delay";
33 34
436 local session, stanza = event.session, event.stanza; 437 local session, stanza = event.session, event.stanza;
437 -- Only deal with authenticated (c2s) sessions 438 -- Only deal with authenticated (c2s) sessions
438 if session.username then 439 if session.username then
439 if stanza.name == "message" and stanza.attr.xmlns == nil and 440 if stanza.name == "message" and stanza.attr.xmlns == nil and
440 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then 441 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
442 -- don't store messages in offline store if they are mam results
443 local mam_result = stanza:get_child("result", xmlns_mam2);
444 if mam_result ~= nil then
445 return true; -- stanza already "handled", don't send an error and don't add it to offline storage
446 end
441 -- do nothing here for normal messages and don't send out "message delivery errors", 447 -- do nothing here for normal messages and don't send out "message delivery errors",
442 -- because messages are already in MAM at this point (no need to frighten users) 448 -- because messages are already in MAM at this point (no need to frighten users)
443 local stanza_id = get_stanza_id(stanza, jid.bare(session.full_jid)); 449 local stanza_id = get_stanza_id(stanza, jid.bare(session.full_jid));
444 if session.mam_requested and stanza_id ~= nil then 450 if session.mam_requested and stanza_id ~= nil then
445 session.log("debug", "mod_smacks delivery/failuere returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id)); 451 session.log("debug", "mod_smacks delivery/failure returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id));
446 return true; -- stanza handled, don't send an error 452 return true; -- stanza handled, don't send an error
447 end 453 end
448 -- store message in offline store, if this client does not use mam *and* was the last client online 454 -- store message in offline store, if this client does not use mam *and* was the last client online
449 local sessions = prosody.hosts[module.host].sessions[session.username] and 455 local sessions = prosody.hosts[module.host].sessions[session.username] and
450 prosody.hosts[module.host].sessions[session.username].sessions or nil; 456 prosody.hosts[module.host].sessions[session.username].sessions or nil;
451 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then 457 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then
452 local ok = module:fire_event("message/offline/handle", { origin = session, stanza = stanza } ); 458 local ok = module:fire_event("message/offline/handle", { origin = session, stanza = stanza } );
453 session.log("debug", "mod_smacks delivery/failuere returning %s for offline-handled stanza", tostring(ok)); 459 session.log("debug", "mod_smacks delivery/failuere returning %s for offline-handled stanza", tostring(ok));
454 return ok; -- if stanza was handled, don't send an error 460 return ok; -- if stanza was handled, don't send an error
455 end 461 end
456 end 462 end
457 end 463 end
458 end); 464 end);
459 465