Software /
code /
prosody-modules
Changeset
2393:3b2c94ea0c2e
mod_delay: initial commit
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Tue, 22 Nov 2016 21:15:01 +0100 |
parents | 2392:d1e975c24545 |
children | 2394:4c27ebcf4cbd |
files | mod_delay/README.markdown mod_delay/mod_delay.lua |
diffstat | 2 files changed, 57 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_delay/README.markdown Tue Nov 22 21:15:01 2016 +0100 @@ -0,0 +1,31 @@ +--- +labels: +- 'Stage-Alpha' +summary: Add "XEP-0203 Delayed Delivery"-tags to every message stanza +... + +Introduction +============ + +This module adds "Delayed Delivery"-tags to every message stanza passing +the server containing the current time on that server. + +This adds accurate message timings even when the message is delayed by slow networks +on the receiving client or by any event. + +Compatibility +============= + + ----- ----------------------------------------------------- + 0.10 Works + ----- ----------------------------------------------------- + + +Clients +======= + +Clients that support XEP-0203 (among others): + +- Gajim +- Conversations +- Yaxim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_delay/mod_delay.lua Tue Nov 22 21:15:01 2016 +0100 @@ -0,0 +1,26 @@ +local add_filter = require "util.filters".add_filter; +local remove_filter = require "util.filters".remove_filter; +local datetime = require "util.datetime"; + +local xmlns_delay = "urn:xmpp:delay"; + +-- Raise an error if the modules has been loaded as a component in prosody's config +if module:get_host_type() == "component" then + error(module.name.." should NOT be loaded as a component, check out http://prosody.im/doc/components", 0); +end + +local add_delay = function(stanza, session) + if stanza and stanza.name == "message" and stanza:get_child("delay", xmlns_delay) == nil then + -- session.log("debug", "adding delay to message %s", tostring(stanza)); + stanza = stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); + end + return stanza; +end + +module:hook("resource-bind", function(event) + add_filter(event.session, "stanzas/in", add_delay, 1); +end); + +module:hook("pre-resource-unbind", function (event) + remove_filter(event.session, "stanzas/in", add_delay); +end);