annotate mod_smacks_noerror/mod_smacks_noerror.lua @ 3221:b98c7c33550e

mod_pep_vcard_avatar: Log error when used with new mod_pep, add compat with mod_pep_simple
author Matthew Wild <mwild1@gmail.com>
date Thu, 09 Aug 2018 22:36:22 +0100
parents f35b2b76df6d
children e7dc25e54d02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2392
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
1 local t_insert = table.insert;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
2
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
3 local mod_smacks = module:depends"smacks"
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
4
3171
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
5 -- ignore offline messages and don't return any error (the message will be already in MAM at this point)
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
6 -- this is *only* triggered if mod_offline is *not* loaded and completely ignored otherwise
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
7 module:hook("message/offline/handle", function(event)
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
8 event.origin.log("debug", "Ignoring offline message (mod_offline seems to be *not* loaded)...");
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
9 return true;
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
10 end, -100);
f35b2b76df6d mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled
tmolitor <thilo@eightysoft.de>
parents: 2392
diff changeset
11
2392
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
12 local function discard_unacked_messages(session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
13 local queue = session.outgoing_stanza_queue;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
14 local replacement_queue = {};
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
15 session.outgoing_stanza_queue = replacement_queue;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
16
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
17 for _, stanza in ipairs(queue) do
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
18 if stanza.name == "message" and stanza.attr.xmlns == nil and
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
19 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
20 -- do nothing here for normal messages and don't send out "message delivery errors",
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
21 -- because messages are already in MAM at this point (no need to frighten users)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
22 else
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
23 t_insert(replacement_queue, stanza);
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
24 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
25 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
26 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
27
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
28 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
29
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
30 mod_smacks.handle_unacked_stanzas = function (session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
31 -- Only deal with authenticated (c2s) sessions
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
32 if session.username then
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
33 discard_unacked_messages(session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
34 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
35 return handle_unacked_stanzas(session);
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
36 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
37
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
38 function module.unload()
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
39 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
40 end