Mercurial > prosody-modules
annotate mod_delay/mod_delay.lua @ 3205:7bfb25111ea6
mod_s2s_auth_posh: Normalize code formatting
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Jan 2018 13:57:02 +0100 |
parents | 5e94061c1aa7 |
children |
rev | line source |
---|---|
3054
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
1 -- Copyright (C) 2016-2017 Thilo Molitor |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
2 -- |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
3 -- This project is MIT/X11 licensed. Please see the |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
4 -- COPYING file in the source package for more information. |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
5 -- |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
6 |
2393 | 7 local add_filter = require "util.filters".add_filter; |
8 local remove_filter = require "util.filters".remove_filter; | |
9 local datetime = require "util.datetime"; | |
10 | |
11 local xmlns_delay = "urn:xmpp:delay"; | |
12 | |
13 -- Raise an error if the modules has been loaded as a component in prosody's config | |
14 if module:get_host_type() == "component" then | |
15 error(module.name.." should NOT be loaded as a component, check out http://prosody.im/doc/components", 0); | |
16 end | |
17 | |
18 local add_delay = function(stanza, session) | |
19 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
|
20 -- 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
|
21 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
|
22 -- 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
|
23 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
|
24 end |
2393 | 25 end |
26 return stanza; | |
27 end | |
28 | |
29 module:hook("resource-bind", function(event) | |
30 add_filter(event.session, "stanzas/in", add_delay, 1); | |
31 end); | |
3054
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
32 module:hook("smacks-hibernation-end", function(event) |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
33 -- older smacks module versions send only the "intermediate" session in event.session and no session.resumed one |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
34 if event.resumed then |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
35 add_filter(event.resumed, "stanzas/in", add_delay, 1); |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
36 end |
5e94061c1aa7
mod_delay: Don't break on smacks resume
tmolitor <thilo@eightysoft.de>
parents:
2435
diff
changeset
|
37 end); |
2393 | 38 module:hook("pre-resource-unbind", function (event) |
39 remove_filter(event.session, "stanzas/in", add_delay); | |
40 end); |