diff options
author | Kim Alvefur <zash@zash.se> | 2021-12-01 15:09:11 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-12-01 15:09:11 +0100 |
commit | 85602802b2d2d7285b25b05bf32fa96cab8afd72 (patch) | |
tree | 7bae5688d80d22e4a326602b84cf0990d4e4e530 /plugins | |
parent | d02e79c6a99ffc318530ded9ace026ee24c10eae (diff) | |
download | prosody-85602802b2d2d7285b25b05bf32fa96cab8afd72.tar.gz prosody-85602802b2d2d7285b25b05bf32fa96cab8afd72.zip |
mod_smacks: Use new pre-session-close event instead of monkeypatch
Much cleaner.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_smacks.lua | 29 |
1 files changed, 16 insertions, 13 deletions
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; |