annotate mod_last_offline/mod_last_offline.lua @ 885:292ea8df7267

mod_admin_web: Let mod_http_files handle file serving
author Kim Alvefur <zash@zash.se>
date Sat, 22 Dec 2012 21:09:41 +0100
parents bec0a995f5df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
883
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local datamanager = require "util.datamanager";
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local time = os.time;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local NULL = {};
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local host = module.host;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 module:hook("resource-unbind", function(event)
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local session = event.session;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 if session.username then
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 datamanager.store(session.username, host, "last_online", {
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 timestamp = time(),
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 });
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end);
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local function offline_stamp(event)
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local stanza = event.stanza;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local node, to_host = jid_split(stanza.attr.from);
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 if to_host == host and event.origin == hosts[host] and stanza.attr.type == "unavailable" then
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local timestamp = (datamanager.load(node, host, "last_online") or NULL).timestamp;
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 if timestamp then
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 stanza:tag("delay", {
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 xmlns = "urn:xmpp:delay",
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 from = host,
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 stamp = datetime.datetime(timestamp),
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 }):up();
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 module:hook("pre-presence/bare", offline_stamp);
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 module:hook("pre-presence/full", offline_stamp);
bec0a995f5df mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33