Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 3450:9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 20 Jan 2019 00:02:08 +0000 |
parents | 67f1d1f22625 |
children | 1f2381492c9f |
comparison
equal
deleted
inserted
replaced
3449:5e91a34b1e71 | 3450:9b6206f23151 |
---|---|
353 origin.log("debug", "Client h: %d, our h: %d", tonumber(stanza.attr.h), origin.last_acknowledged_stanza); | 353 origin.log("debug", "Client h: %d, our h: %d", tonumber(stanza.attr.h), origin.last_acknowledged_stanza); |
354 for i=1,#queue do | 354 for i=1,#queue do |
355 origin.log("debug", "Q item %d: %s", i, tostring(queue[i])); | 355 origin.log("debug", "Q item %d: %s", i, tostring(queue[i])); |
356 end | 356 end |
357 end | 357 end |
358 | |
358 for i=1,math_min(handled_stanza_count,#queue) do | 359 for i=1,math_min(handled_stanza_count,#queue) do |
359 t_remove(origin.outgoing_stanza_queue, 1); | 360 local handled_stanza = t_remove(origin.outgoing_stanza_queue, 1); |
360 end | 361 module:fire_event("delivery/success", { session = origin, stanza = handled_stanza }); |
362 end | |
363 | |
361 origin.log("debug", "#queue = %d", #queue); | 364 origin.log("debug", "#queue = %d", #queue); |
362 origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; | 365 origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; |
363 request_ack_if_needed(origin, false) | 366 request_ack_if_needed(origin, false) |
364 return true; | 367 return true; |
365 end | 368 end |
375 local queue = session.outgoing_stanza_queue; | 378 local queue = session.outgoing_stanza_queue; |
376 local error_attr = { type = "cancel" }; | 379 local error_attr = { type = "cancel" }; |
377 if #queue > 0 then | 380 if #queue > 0 then |
378 session.outgoing_stanza_queue = {}; | 381 session.outgoing_stanza_queue = {}; |
379 for i=1,#queue do | 382 for i=1,#queue do |
380 local reply = st.reply(queue[i]); | 383 if not module:fire_event("delivery/failure", { session = session, stanza = queue[i] }) then |
381 if reply.attr.to ~= session.full_jid then | 384 local reply = st.reply(queue[i]); |
382 reply.attr.type = "error"; | 385 if reply.attr.to ~= session.full_jid then |
383 reply:tag("error", error_attr) | 386 reply.attr.type = "error"; |
384 :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); | 387 reply:tag("error", error_attr) |
385 core_process_stanza(session, reply); | 388 :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); |
389 core_process_stanza(session, reply); | |
390 end | |
386 end | 391 end |
387 end | 392 end |
388 end | 393 end |
389 end | 394 end |
390 | 395 |