mod_csi_simple: Break out stanza timestamping into a function for future reuse
authorKim Alvefur <zash@zash.se>
Sun, 24 Mar 2019 18:32:50 +0100
changeset 9915 ed011935c22d
parent 9914 7a703af90c9c
child 9916 601f9781a605
mod_csi_simple: Break out stanza timestamping into a function for future reuse
plugins/mod_csi_simple.lua
--- a/plugins/mod_csi_simple.lua	Sun Mar 24 18:30:51 2019 +0100
+++ b/plugins/mod_csi_simple.lua	Sun Mar 24 18:32:50 2019 +0100
@@ -84,6 +84,14 @@
 	return true;
 end, -1);
 
+local function with_timestamp(stanza, from)
+	if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then
+		stanza = st.clone(stanza);
+		stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = from, stamp = dt.datetime()}));
+	end
+	return stanza;
+end
+
 module:hook("csi-client-inactive", function (event)
 	local session = event.origin;
 	if session.conn and session.conn and session.conn.pause_writes then
@@ -102,11 +110,7 @@
 				pump:flush();
 				send(stanza);
 			else
-				if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then
-					stanza = st.clone(stanza);
-					stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = bare_jid, stamp = dt.datetime()}));
-				end
-				pump:push(stanza);
+				pump:push(with_timestamp(stanza, bare_jid));
 			end
 			return true;
 		end