Mercurial > prosody-modules
comparison mod_idlecompat/mod_idlecompat.lua @ 1260:4e14ad802d58
mod_idlecompat: Add initial version.
Add XEP-0319 tags based on XEP-0012 tags for presence stanzas.
| author | Tobias Markmann <tm@ayena.de> |
|---|---|
| date | Fri, 03 Jan 2014 11:54:13 +0100 |
| parents | |
| children | 4b58e35a72e0 |
comparison
equal
deleted
inserted
replaced
| 1259:fa7e402fcdc1 | 1260:4e14ad802d58 |
|---|---|
| 1 -- Last User Interaction in Presence via Last Activity compatibility module | |
| 2 -- http://xmpp.org/extensions/xep-0319.html | |
| 3 -- http://xmpp.org/extensions/xep-0012.html | |
| 4 -- Copyright (C) 2014 Tobias Markmann | |
| 5 -- | |
| 6 -- This file is MIT/X11 licensed. | |
| 7 | |
| 8 local st = require "util.stanza"; | |
| 9 local datetime = require "util.datetime"; | |
| 10 | |
| 11 local function on_presence(event) | |
| 12 local stanza = event.stanza; | |
| 13 | |
| 14 local last_activity = stanza.name == "presence" and stanza:get_child("query", "jabber:iq:last") or false; | |
| 15 local has_idle = stanza:get_child("idle", "urn:xmpp:idle:1"); | |
| 16 if last_activity and not has_idle then | |
| 17 module:log("debug", "Adding XEP-0319 tag from Last Activity."); | |
| 18 local seconds = last_activity.attr.seconds; | |
| 19 local last_userinteraction = datetime.datetime(os.time() - seconds); | |
| 20 stanza:tag("idle", { xmlns = "urn:xmpp:idle:1", since = last_userinteraction }):up(); | |
| 21 end | |
| 22 end | |
| 23 | |
| 24 -- incoming | |
| 25 module:hook("presence/full", on_presence, 900); | |
| 26 module:hook("presence/bare", on_presence, 900); | |
| 27 | |
| 28 -- outgoing | |
| 29 module:hook("pre-presence/bare", on_presence, 900); | |
| 30 module:hook("pre-presence/full", on_presence, 900); | |
| 31 module:hook("pre-presence/host", on_presence, 900); |
