Mercurial > prosody-modules
comparison mod_smacks_noerror/mod_smacks_noerror.lua @ 3937:e7dc25e54d02
mod_smacks_noerror: This module is superseded by mod_smacks and mod_nooffline_noerror
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Sun, 08 Mar 2020 19:52:33 +0100 |
| parents | f35b2b76df6d |
| children |
comparison
equal
deleted
inserted
replaced
| 3936:a3693e0d26b8 | 3937:e7dc25e54d02 |
|---|---|
| 1 local t_insert = table.insert; | 1 -- this module is deprecated, log an error and load the superseding modules instead |
| 2 module:depends"smacks" | |
| 3 module:depends"nooffline_noerror" | |
| 2 | 4 |
| 3 local mod_smacks = module:depends"smacks" | 5 module:log("error", "mod_smacks_noerror is deprecated! Just use mod_smacks and load mod_nooffline_noerror if you explicitly disabled offline storage (mod_offline)"); |
| 4 | |
| 5 -- ignore offline messages and don't return any error (the message will be already in MAM at this point) | |
| 6 -- this is *only* triggered if mod_offline is *not* loaded and completely ignored otherwise | |
| 7 module:hook("message/offline/handle", function(event) | |
| 8 event.origin.log("debug", "Ignoring offline message (mod_offline seems to be *not* loaded)..."); | |
| 9 return true; | |
| 10 end, -100); | |
| 11 | |
| 12 local function discard_unacked_messages(session) | |
| 13 local queue = session.outgoing_stanza_queue; | |
| 14 local replacement_queue = {}; | |
| 15 session.outgoing_stanza_queue = replacement_queue; | |
| 16 | |
| 17 for _, stanza in ipairs(queue) do | |
| 18 if stanza.name == "message" and stanza.attr.xmlns == nil and | |
| 19 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then | |
| 20 -- do nothing here for normal messages and don't send out "message delivery errors", | |
| 21 -- because messages are already in MAM at this point (no need to frighten users) | |
| 22 else | |
| 23 t_insert(replacement_queue, stanza); | |
| 24 end | |
| 25 end | |
| 26 end | |
| 27 | |
| 28 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas; | |
| 29 | |
| 30 mod_smacks.handle_unacked_stanzas = function (session) | |
| 31 -- Only deal with authenticated (c2s) sessions | |
| 32 if session.username then | |
| 33 discard_unacked_messages(session) | |
| 34 end | |
| 35 return handle_unacked_stanzas(session); | |
| 36 end | |
| 37 | |
| 38 function module.unload() | |
| 39 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas; | |
| 40 end |
