# HG changeset patch # User Kim Alvefur # Date 1553448770 -3600 # Node ID ed011935c22da8043abc481f2fbf7d6fcc347218 # Parent 7a703af90c9c17135da1ed26b8ada1a1992f0a9b mod_csi_simple: Break out stanza timestamping into a function for future reuse diff -r 7a703af90c9c -r ed011935c22d 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