Mercurial > prosody-modules
comparison mod_smacks_offline/mod_smacks_offline.lua @ 1702:725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 06 May 2015 00:55:00 +0200 |
parents | |
children | b912cb8e0b3c |
comparison
equal
deleted
inserted
replaced
1701:9b429fc9e8a0 | 1702:725ebd494000 |
---|---|
1 local t_insert = table.insert; | |
2 | |
3 local mod_smacks = module:depends"smacks" | |
4 | |
5 local function store_unacked_stanzas(session) | |
6 local queue = session.outgoing_stanza_queue; | |
7 local replacement_queue = {}; | |
8 session.outgoing_stanza_queue = replacement_queue; | |
9 | |
10 for _, stanza in ipairs(queue) do | |
11 if stanza.name == "message" and stanza.attr.xmlns == nil and | |
12 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then | |
13 module:fire_event("message/offline/handle", { origin = session, stanza = stanza } ) | |
14 else | |
15 t_insert(replacement_queue, stanza); | |
16 end | |
17 end | |
18 end | |
19 | |
20 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas; | |
21 | |
22 local host_sessions = prosody.hosts[module.host].sessions; | |
23 mod_smacks.handle_unacked_stanzas = function (session) | |
24 local sessions = host_sessions[session.username].sessions; | |
25 if next(sessions) == session.resource and next(sessions, session.resource) == nil then | |
26 store_unacked_stanzas(session) | |
27 end | |
28 return handle_unacked_stanzas(session); | |
29 end | |
30 | |
31 function module.unload() | |
32 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas; | |
33 end |