Comparison

mod_smacks_noerror/mod_smacks_noerror.lua @ 2392:d1e975c24545

mod_smacks_noerror: Initial commit
author tmolitor <thilo@eightysoft.de>
date Tue, 22 Nov 2016 21:14:47 +0100
child 3171:f35b2b76df6d
comparison
equal deleted inserted replaced
2391:85d04dd87f14 2392:d1e975c24545
1 local t_insert = table.insert;
2
3 local mod_smacks = module:depends"smacks"
4
5 local function discard_unacked_messages(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 -- do nothing here for normal messages and don't send out "message delivery errors",
14 -- because messages are already in MAM at this point (no need to frighten users)
15 else
16 t_insert(replacement_queue, stanza);
17 end
18 end
19 end
20
21 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas;
22
23 mod_smacks.handle_unacked_stanzas = function (session)
24 -- Only deal with authenticated (c2s) sessions
25 if session.username then
26 discard_unacked_messages(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