<commit_before><commit_msg>mod_last_offline: New module that stores last logut time and attaches this timestamp to unavailable presence.<commit_after>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);

{'fraction_non_alphanumeric': 0.12942271880819367, 'fraction_numerical': 0.0, 'mean_word_length': 5.073446327683616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5434304', 'n_tokens_mistral': 375, 'n_tokens_neox': 349, 'n_words': 90}