# HG changeset patch # User Kim Alvefur # Date 1370285646 -7200 # Node ID 59f031d1cd3822e2f7394ed876ab7f6fc4e9b43c # Parent 50bed746aa1618c146db50d75cf258c3170af30b mod_last_offline: Merge into an option of mod_lastlog diff -r 50bed746aa16 -r 59f031d1cd38 mod_last_offline/mod_last_offline.lua --- a/mod_last_offline/mod_last_offline.lua Mon Jun 03 19:35:13 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -local datamanager = require "util.datamanager"; -local jid_split = require "util.jid".split; -local time = os.time; -local NULL = {}; -local host = module.host; - -module:hook("resource-unbind", function(event) - local session = event.session; - if session.username then - datamanager.store(session.username, host, "last_online", { - timestamp = time(), - }); - end -end); - -local function offline_stamp(event) - local stanza = event.stanza; - local node, to_host = jid_split(stanza.attr.from); - if to_host == host and event.origin == hosts[host] and stanza.attr.type == "unavailable" then - local timestamp = (datamanager.load(node, host, "last_online") or NULL).timestamp; - if timestamp then - stanza:tag("delay", { - xmlns = "urn:xmpp:delay", - from = host, - stamp = datetime.datetime(timestamp), - }):up(); - end - end -end - -module:hook("pre-presence/bare", offline_stamp); -module:hook("pre-presence/full", offline_stamp); - diff -r 50bed746aa16 -r 59f031d1cd38 mod_lastlog/mod_lastlog.lua --- a/mod_lastlog/mod_lastlog.lua Mon Jun 03 19:35:13 2013 +0200 +++ b/mod_lastlog/mod_lastlog.lua Mon Jun 03 20:54:06 2013 +0200 @@ -1,4 +1,5 @@ local datamanager = require "util.datamanager"; +local jid = require "util.jid"; local time = os.time; local log_ip = module:get_option_boolean("lastlog_ip_address", false); local host = module.host; @@ -25,8 +26,29 @@ end end); +if module:get_option_boolean("lastlog_stamp_offline") then + local function offline_stamp(event) + local stanza = event.stanza; + local node, to_host = jid.split(stanza.attr.from); + if to_host == host and event.origin == hosts[host] and stanza.attr.type == "unavailable" then + local data = datamanager.load(node, host, "lastlog"); + local timestamp = data and data.timestamp; + if timestamp then + stanza:tag("delay", { + xmlns = "urn:xmpp:delay", + from = host, + stamp = datetime.datetime(timestamp), + }):up(); + end + end + end + + module:hook("pre-presence/bare", offline_stamp); + module:hook("pre-presence/full", offline_stamp); +end + function module.command(arg) - local user, host = require "util.jid".prepped_split(table.remove(arg, 1)); + local user, host = jid.prepped_split(table.remove(arg, 1)); require"core.storagemanager".initialize_host(host); local lastlog = assert(datamanager.load(user, host, "lastlog")); if lastlog then