157 session.pump = pump; |
157 session.pump = pump; |
158 session._pump_orig_send = session.send; |
158 session._pump_orig_send = session.send; |
159 function session.send(stanza) |
159 function session.send(stanza) |
160 session.log("debug", "mod_csi_battery_saver(%s): Got stanza: <%s>", id, tostring(stanza.name or stanza)); |
160 session.log("debug", "mod_csi_battery_saver(%s): Got stanza: <%s>", id, tostring(stanza.name or stanza)); |
161 local important = is_important(stanza, session); |
161 local important = is_important(stanza, session); |
|
162 -- clone stanzas before adding delay stamp and putting them into the queue |
|
163 if st.is_stanza(stanza) then stanza = st.clone(stanza); end |
162 -- add delay stamp to unimportant (buffered) stanzas that can/need be stamped |
164 -- add delay stamp to unimportant (buffered) stanzas that can/need be stamped |
163 if not important and is_stamp_needed(stanza, session) then stanza = add_stamp(stanza, session); end |
165 if not important and is_stamp_needed(stanza, session) then stanza = add_stamp(stanza, session); end |
|
166 -- add stanza to outgoing queue and flush the buffer if needed |
164 pump:push(stanza); |
167 pump:push(stanza); |
165 if important then |
168 if important then |
166 session.log("debug", "mod_csi_battery_saver(%s): Encountered important stanza, flushing buffer: <%s>", id, tostring(stanza.name or stanza)); |
169 session.log("debug", "mod_csi_battery_saver(%s): Encountered important stanza, flushing buffer: <%s>", id, tostring(stanza.name or stanza)); |
167 pump:flush(); |
170 pump:flush(); |
168 end |
171 end |