annotate mod_smacks_noerror/mod_smacks_noerror.lua @ 2752:d0e75bf21d30

mod_delegation: added disco#items support disco#items are forwarded to managing entity when suitable. This feature is not yet in XEP-0355, but it should be added soon. "http://jabber.org/protocol/disco#items:*" is used as a pseudo-namespace to activate this delegation. Also changed spaces to tabs to follow Prosody coding style.
author Goffi <goffi@goffi.org>
date Sun, 27 Aug 2017 20:46:04 +0200
parents d1e975c24545
children f35b2b76df6d
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
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
5 local function discard_unacked_messages(session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
6 local queue = session.outgoing_stanza_queue;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
7 local replacement_queue = {};
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
8 session.outgoing_stanza_queue = replacement_queue;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
9
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
10 for _, stanza in ipairs(queue) do
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
11 if stanza.name == "message" and stanza.attr.xmlns == nil and
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
12 ( 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
13 -- 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
14 -- 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
15 else
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
16 t_insert(replacement_queue, stanza);
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
17 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
18 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
19 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
20
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
21 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
22
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
23 mod_smacks.handle_unacked_stanzas = function (session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
24 -- Only deal with authenticated (c2s) sessions
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
25 if session.username then
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
26 discard_unacked_messages(session)
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
27 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
28 return handle_unacked_stanzas(session);
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
29 end
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
30
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
31 function module.unload()
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
32 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas;
d1e975c24545 mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff changeset
33 end