Software /
code /
prosody-modules
Comparison
mod_last_offline/mod_last_offline.lua @ 883:bec0a995f5df
mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 20 Dec 2012 12:12:36 +0100 |
comparison
equal
deleted
inserted
replaced
882:4939788a47ea | 883:bec0a995f5df |
---|---|
1 local datamanager = require "util.datamanager"; | |
2 local jid_split = require "util.jid".split; | |
3 local time = os.time; | |
4 local NULL = {}; | |
5 local host = module.host; | |
6 | |
7 module:hook("resource-unbind", function(event) | |
8 local session = event.session; | |
9 if session.username then | |
10 datamanager.store(session.username, host, "last_online", { | |
11 timestamp = time(), | |
12 }); | |
13 end | |
14 end); | |
15 | |
16 local function offline_stamp(event) | |
17 local stanza = event.stanza; | |
18 local node, to_host = jid_split(stanza.attr.from); | |
19 if to_host == host and event.origin == hosts[host] and stanza.attr.type == "unavailable" then | |
20 local timestamp = (datamanager.load(node, host, "last_online") or NULL).timestamp; | |
21 if timestamp then | |
22 stanza:tag("delay", { | |
23 xmlns = "urn:xmpp:delay", | |
24 from = host, | |
25 stamp = datetime.datetime(timestamp), | |
26 }):up(); | |
27 end | |
28 end | |
29 end | |
30 | |
31 module:hook("pre-presence/bare", offline_stamp); | |
32 module:hook("pre-presence/full", offline_stamp); | |
33 |