view mod_idlecompat/mod_idlecompat.lua @ 1268:854a3933cfcd

mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 04 Jan 2014 16:50:57 -0500
parents 4e14ad802d58
children 4b58e35a72e0
line wrap: on
line source

-- Last User Interaction in Presence via Last Activity compatibility module
-- http://xmpp.org/extensions/xep-0319.html
-- http://xmpp.org/extensions/xep-0012.html
-- Copyright (C) 2014 Tobias Markmann
--
-- This file is MIT/X11 licensed.

local st = require "util.stanza";
local datetime = require "util.datetime";

local function on_presence(event)
	local stanza = event.stanza;

	local last_activity = stanza.name == "presence" and stanza:get_child("query", "jabber:iq:last") or false;
	local has_idle = stanza:get_child("idle", "urn:xmpp:idle:1");
	if last_activity and not has_idle then
		module:log("debug", "Adding XEP-0319 tag from Last Activity.");
		local seconds = last_activity.attr.seconds;
		local last_userinteraction = datetime.datetime(os.time() - seconds);
		stanza:tag("idle", { xmlns = "urn:xmpp:idle:1", since = last_userinteraction }):up();
	end
end

-- incoming
module:hook("presence/full", on_presence, 900);
module:hook("presence/bare", on_presence, 900);

-- outgoing
module:hook("pre-presence/bare", on_presence, 900);
module:hook("pre-presence/full", on_presence, 900);
module:hook("pre-presence/host", on_presence, 900);