Mercurial > prosody-hg
comparison plugins/mod_smacks.lua @ 12114:e32f90c81519
mod_smacks: Compact code using new stanza API
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 22 Dec 2021 22:13:03 +0100 |
| parents | 08a949e63541 |
| children | 649268c9f603 |
comparison
equal
deleted
inserted
replaced
| 12113:86e6f0810956 | 12114:e32f90c81519 |
|---|---|
| 374 end | 374 end |
| 375 | 375 |
| 376 -- don't send delivery errors for messages which will be delivered by mam later on | 376 -- don't send delivery errors for messages which will be delivered by mam later on |
| 377 -- check if stanza was archived --> this will allow us to send back errors for stanzas not archived | 377 -- check if stanza was archived --> this will allow us to send back errors for stanzas not archived |
| 378 -- because the user configured the server to do so ("no-archive"-setting for one special contact for example) | 378 -- because the user configured the server to do so ("no-archive"-setting for one special contact for example) |
| 379 local function get_stanza_id(stanza, by_jid) | |
| 380 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do | |
| 381 if tag.attr.by == by_jid then | |
| 382 return tag.attr.id; | |
| 383 end | |
| 384 end | |
| 385 return nil; | |
| 386 end | |
| 387 module:hook("delivery/failure", function(event) | 379 module:hook("delivery/failure", function(event) |
| 388 local session, stanza = event.session, event.stanza; | 380 local session, stanza = event.session, event.stanza; |
| 389 -- Only deal with authenticated (c2s) sessions | 381 -- Only deal with authenticated (c2s) sessions |
| 390 if session.username then | 382 if session.username then |
| 391 if stanza.name == "message" and stanza.attr.xmlns == nil and | 383 if stanza.name == "message" and stanza.attr.xmlns == nil and |
| 395 if mam_result ~= nil then | 387 if mam_result ~= nil then |
| 396 return true; -- stanza already "handled", don't send an error and don't add it to offline storage | 388 return true; -- stanza already "handled", don't send an error and don't add it to offline storage |
| 397 end | 389 end |
| 398 -- do nothing here for normal messages and don't send out "message delivery errors", | 390 -- do nothing here for normal messages and don't send out "message delivery errors", |
| 399 -- because messages are already in MAM at this point (no need to frighten users) | 391 -- because messages are already in MAM at this point (no need to frighten users) |
| 400 local stanza_id = get_stanza_id(stanza, jid.bare(session.full_jid)); | 392 local stanza_id = stanza:get_child_with_attr("stanza-id", "urn:xmpp:sid:0", "by", jid.bare(session.full_jid)); |
| 393 stanza_id = stanza_id and stanza_id.attr.id; | |
| 401 if session.mam_requested and stanza_id ~= nil then | 394 if session.mam_requested and stanza_id ~= nil then |
| 402 session.log("debug", "mod_smacks delivery/failure returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id)); | 395 session.log("debug", "mod_smacks delivery/failure returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id)); |
| 403 return true; -- stanza handled, don't send an error | 396 return true; -- stanza handled, don't send an error |
| 404 end | 397 end |
| 405 -- store message in offline store, if this client does not use mam *and* was the last client online | 398 -- store message in offline store, if this client does not use mam *and* was the last client online |
