Comparison

plugins/mod_smacks.lua @ 11975:fcea4d9e7502

mod_smacks: Use new pre-session-close event instead of monkeypatch Much cleaner.
author Kim Alvefur <zash@zash.se>
date Wed, 01 Dec 2021 15:09:11 +0100
parent 11952:b78a341e72e7
child 11976:10cdfb94f1cc
comparison
equal deleted inserted replaced
11974:a7c183bb4e64 11975:fcea4d9e7502
254 session.last_acknowledged_stanza = 0; 254 session.last_acknowledged_stanza = 0;
255 end 255 end
256 256
257 add_filter(session, "stanzas/out", outgoing_stanza_filter, -999); 257 add_filter(session, "stanzas/out", outgoing_stanza_filter, -999);
258 258
259 local session_close = session.close;
260 function session.close(...)
261 if session.resumption_token then
262 session_registry.set(session.username, session.resumption_token, nil);
263 old_session_registry.set(session.username, session.resumption_token, nil);
264 session.resumption_token = nil;
265 end
266 -- send out last ack as per revision 1.5.2 of XEP-0198
267 if session.smacks and session.conn and session.handled_stanza_count then
268 (session.sends2s or session.send)(st.stanza("a", { xmlns = session.smacks, h = string.format("%d", session.handled_stanza_count) }));
269 end
270 return session_close(...);
271 end
272 return session; 259 return session;
273 end 260 end
261
262 module:hook("pre-session-close", function(event)
263 local session = event.session;
264 if session.resumption_token then
265 session_registry.set(session.username, session.resumption_token, nil);
266 old_session_registry.set(session.username, session.resumption_token, nil);
267 session.resumption_token = nil;
268 end
269 -- send out last ack as per revision 1.5.2 of XEP-0198
270 if session.smacks and session.conn and session.handled_stanza_count then
271 (session.sends2s or session.send)(st.stanza("a", {
272 xmlns = session.smacks;
273 h = string.format("%d", session.handled_stanza_count);
274 }));
275 end
276 end);
274 277
275 local function wrap_session_in(session, resume) 278 local function wrap_session_in(session, resume)
276 if not resume then 279 if not resume then
277 session.handled_stanza_count = 0; 280 session.handled_stanza_count = 0;
278 end 281 end