Changeset

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 3449:5e91a34b1e71
children 3451:7b97abf26612
files mod_smacks/mod_smacks.lua
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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