Mercurial > prosody-modules
annotate mod_delay/mod_delay.lua @ 2491:5fbca7de2088
mod_smacks: Send out more ack requests where needed
Under some circumstances it was possible that more than "max_unacked_stanzas"
where left in the outgoing stanza queue without forcing an ack.
This could happen, when more stanzas entered the queue while the last ack request
was still unanswered.
Now the test "#queue > max_unacked_stanzas" is done upon receiving
an ack as well as when sending out stanzas, which fixes this bug.
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Sun, 12 Feb 2017 19:27:50 +0100 |
| parents | 05248d5a7166 |
| children | 5e94061c1aa7 |
| rev | line source |
|---|---|
| 2393 | 1 local add_filter = require "util.filters".add_filter; |
| 2 local remove_filter = require "util.filters".remove_filter; | |
| 3 local datetime = require "util.datetime"; | |
| 4 | |
| 5 local xmlns_delay = "urn:xmpp:delay"; | |
| 6 | |
| 7 -- Raise an error if the modules has been loaded as a component in prosody's config | |
| 8 if module:get_host_type() == "component" then | |
| 9 error(module.name.." should NOT be loaded as a component, check out http://prosody.im/doc/components", 0); | |
| 10 end | |
| 11 | |
| 12 local add_delay = function(stanza, session) | |
| 13 if stanza and stanza.name == "message" and stanza:get_child("delay", xmlns_delay) == nil then | |
|
2435
05248d5a7166
mod_delay: Only add delay to messages of type chat or groupchat (fixes #811)
tmolitor <thilo@eightysoft.de>
parents:
2393
diff
changeset
|
14 -- only add delay tag to chat or groupchat messages (should we add a delay to anything else, too???) |
|
05248d5a7166
mod_delay: Only add delay to messages of type chat or groupchat (fixes #811)
tmolitor <thilo@eightysoft.de>
parents:
2393
diff
changeset
|
15 if stanza.attr.type == "chat" or stanza.attr.type == "groupchat" then |
|
05248d5a7166
mod_delay: Only add delay to messages of type chat or groupchat (fixes #811)
tmolitor <thilo@eightysoft.de>
parents:
2393
diff
changeset
|
16 -- session.log("debug", "adding delay to message %s", tostring(stanza)); |
|
05248d5a7166
mod_delay: Only add delay to messages of type chat or groupchat (fixes #811)
tmolitor <thilo@eightysoft.de>
parents:
2393
diff
changeset
|
17 stanza = stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); |
|
05248d5a7166
mod_delay: Only add delay to messages of type chat or groupchat (fixes #811)
tmolitor <thilo@eightysoft.de>
parents:
2393
diff
changeset
|
18 end |
| 2393 | 19 end |
| 20 return stanza; | |
| 21 end | |
| 22 | |
| 23 module:hook("resource-bind", function(event) | |
| 24 add_filter(event.session, "stanzas/in", add_delay, 1); | |
| 25 end); | |
| 26 | |
| 27 module:hook("pre-resource-unbind", function (event) | |
| 28 remove_filter(event.session, "stanzas/in", add_delay); | |
| 29 end); |
