# HG changeset patch # User Matthew Wild # Date 1547942528 0 # Node ID 9b6206f231513f2a9b1258a499c7c823dab4aa68 # Parent 5e91a34b1e71b2a9c77be19f07310dad74769d58 mod_smacks: Fire event on delivery failure/success for each stanza diff -r 5e91a34b1e71 -r 9b6206f23151 mod_smacks/mod_smacks.lua --- a/mod_smacks/mod_smacks.lua Fri Jan 18 18:28:03 2019 +0100 +++ b/mod_smacks/mod_smacks.lua Sun Jan 20 00:02:08 2019 +0000 @@ -355,9 +355,12 @@ origin.log("debug", "Q item %d: %s", i, tostring(queue[i])); end end + for i=1,math_min(handled_stanza_count,#queue) do - t_remove(origin.outgoing_stanza_queue, 1); + local handled_stanza = t_remove(origin.outgoing_stanza_queue, 1); + module:fire_event("delivery/success", { session = origin, stanza = handled_stanza }); end + origin.log("debug", "#queue = %d", #queue); origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; request_ack_if_needed(origin, false) @@ -377,12 +380,14 @@ if #queue > 0 then session.outgoing_stanza_queue = {}; for i=1,#queue do - local reply = st.reply(queue[i]); - if reply.attr.to ~= session.full_jid then - reply.attr.type = "error"; - reply:tag("error", error_attr) - :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); - core_process_stanza(session, reply); + if not module:fire_event("delivery/failure", { session = session, stanza = queue[i] }) then + local reply = st.reply(queue[i]); + if reply.attr.to ~= session.full_jid then + reply.attr.type = "error"; + reply:tag("error", error_attr) + :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); + core_process_stanza(session, reply); + end end end end