Software / code / prosody
Comparison
plugins/mod_csi_simple.lua @ 9911:ed011935c22d
mod_csi_simple: Break out stanza timestamping into a function for future reuse
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 24 Mar 2019 18:32:50 +0100 |
| parent | 9909:3229be01a08a |
| child | 9912:601f9781a605 |
comparison
equal
deleted
inserted
replaced
| 9910:7a703af90c9c | 9911:ed011935c22d |
|---|---|
| 82 return false; | 82 return false; |
| 83 end | 83 end |
| 84 return true; | 84 return true; |
| 85 end, -1); | 85 end, -1); |
| 86 | 86 |
| 87 local function with_timestamp(stanza, from) | |
| 88 if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then | |
| 89 stanza = st.clone(stanza); | |
| 90 stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = from, stamp = dt.datetime()})); | |
| 91 end | |
| 92 return stanza; | |
| 93 end | |
| 94 | |
| 87 module:hook("csi-client-inactive", function (event) | 95 module:hook("csi-client-inactive", function (event) |
| 88 local session = event.origin; | 96 local session = event.origin; |
| 89 if session.conn and session.conn and session.conn.pause_writes then | 97 if session.conn and session.conn and session.conn.pause_writes then |
| 90 session.conn:pause_writes(); | 98 session.conn:pause_writes(); |
| 91 elseif session.pump then | 99 elseif session.pump then |
| 100 function session.send(stanza) | 108 function session.send(stanza) |
| 101 if session.state == "active" or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then | 109 if session.state == "active" or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then |
| 102 pump:flush(); | 110 pump:flush(); |
| 103 send(stanza); | 111 send(stanza); |
| 104 else | 112 else |
| 105 if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then | 113 pump:push(with_timestamp(stanza, bare_jid)); |
| 106 stanza = st.clone(stanza); | |
| 107 stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = bare_jid, stamp = dt.datetime()})); | |
| 108 end | |
| 109 pump:push(stanza); | |
| 110 end | 114 end |
| 111 return true; | 115 return true; |
| 112 end | 116 end |
| 113 end | 117 end |
| 114 end); | 118 end); |