From 85602802b2d2d7285b25b05bf32fa96cab8afd72 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Dec 2021 15:09:11 +0100 Subject: mod_smacks: Use new pre-session-close event instead of monkeypatch Much cleaner. --- plugins/mod_smacks.lua | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_smacks.lua b/plugins/mod_smacks.lua index f7528da1..ee07ac13 100644 --- a/plugins/mod_smacks.lua +++ b/plugins/mod_smacks.lua @@ -256,22 +256,25 @@ local function wrap_session_out(session, resume) add_filter(session, "stanzas/out", outgoing_stanza_filter, -999); - local session_close = session.close; - function session.close(...) - if session.resumption_token then - session_registry.set(session.username, session.resumption_token, nil); - old_session_registry.set(session.username, session.resumption_token, nil); - session.resumption_token = nil; - end - -- send out last ack as per revision 1.5.2 of XEP-0198 - if session.smacks and session.conn and session.handled_stanza_count then - (session.sends2s or session.send)(st.stanza("a", { xmlns = session.smacks, h = string.format("%d", session.handled_stanza_count) })); - end - return session_close(...); - end return session; end +module:hook("pre-session-close", function(event) + local session = event.session; + if session.resumption_token then + session_registry.set(session.username, session.resumption_token, nil); + old_session_registry.set(session.username, session.resumption_token, nil); + session.resumption_token = nil; + end + -- send out last ack as per revision 1.5.2 of XEP-0198 + if session.smacks and session.conn and session.handled_stanza_count then + (session.sends2s or session.send)(st.stanza("a", { + xmlns = session.smacks; + h = string.format("%d", session.handled_stanza_count); + })); + end +end); + local function wrap_session_in(session, resume) if not resume then session.handled_stanza_count = 0; -- cgit v1.2.3