# HG changeset patch # User tmolitor # Date 1479845701 -3600 # Node ID 3b2c94ea0c2ede2776822165a735186d89fbc1fd # Parent d1e975c24545a3d190c5c4a001444b819cc6037f mod_delay: initial commit diff -r d1e975c24545 -r 3b2c94ea0c2e mod_delay/README.markdown --- /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 diff -r d1e975c24545 -r 3b2c94ea0c2e mod_delay/mod_delay.lua --- /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);