comparison mod_smacks/mod_smacks.lua @ 3983:effe2d93a59c

mod_smacks: Fix mam handling
author tmolitor <thilo@eightysoft.de>
date Mon, 20 Apr 2020 14:40:09 +0200
parents bf5d91769f99
children 4e5fde519116
comparison
equal deleted inserted replaced
3982:ab065ff4628b 3983:effe2d93a59c
418 end 418 end
419 end 419 end
420 end 420 end
421 421
422 -- don't send delivery errors for messages which will be delivered by mam later on 422 -- don't send delivery errors for messages which will be delivered by mam later on
423 local function has_stanza_id(stanza, by_jid)
424 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do
425 if tag.attr.by == by_jid and tag.attr.id then
426 return true
427 end
428 end
429 return false;
430
431 end
423 module:hook("delivery/failure", function(event) 432 module:hook("delivery/failure", function(event)
424 local session, stanza = event.session, event.stanza; 433 local session, stanza = event.session, event.stanza;
425 -- Only deal with authenticated (c2s) sessions 434 -- Only deal with authenticated (c2s) sessions
426 if session.username then 435 if session.username then
427 if stanza.name == "message" and stanza.attr.xmlns == nil and 436 if stanza.name == "message" and stanza.attr.xmlns == nil and
428 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then 437 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
429 -- do nothing here for normal messages and don't send out "message delivery errors", 438 -- do nothing here for normal messages and don't send out "message delivery errors",
430 -- because messages are already in MAM at this point (no need to frighten users) 439 -- because messages are already in MAM at this point (no need to frighten users)
431 if session.mam_requested and stanza._was_archived then 440 if session.mam_requested and has_stanza_id(stanza, jid.bare(session.full_jid) then
441 session.log("debug", "mod_smacks delivery/failuere returning true for mam-handled stanza");
432 return true; -- stanza handled, don't send an error 442 return true; -- stanza handled, don't send an error
433 end 443 end
434 -- store message in offline store, if this client does not use mam *and* was the last client online 444 -- store message in offline store, if this client does not use mam *and* was the last client online
435 local sessions = prosody.hosts[module.host].sessions[session.username] and 445 local sessions = prosody.hosts[module.host].sessions[session.username] and
436 prosody.hosts[module.host].sessions[session.username].sessions or nil; 446 prosody.hosts[module.host].sessions[session.username].sessions or nil;
437 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then 447 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then
438 module:fire_event("message/offline/handle", { origin = session, stanza = stanza } ); 448 local ok = module:fire_event("message/offline/handle", { origin = session, stanza = stanza } );
439 return true; -- stanza handled, don't send an error 449 session.log("debug", "mod_smacks delivery/failuere returning %s for offline-handled stanza", tostring(ok));
450 return ok; -- if stanza was handled, don't send an error
440 end 451 end
441 end 452 end
442 end 453 end
443 end); 454 end);
444 455