File

mod_track_muc_joins/mod_track_muc_joins.lua @ 2083:fed0a71a5e68

mod_http_muc_log: Add XMPP URI link for joining the current room
author Kim Alvefur <zash@zash.se>
date Tue, 15 Mar 2016 16:46:02 +0100
parent 2081:73096d8d924c
child 2085:8cb8004091f8
line wrap: on
line source


module:hook("presence/full", function (event)
	local stanza = event.stanza;
	local session = sessions[stanza.attr.to];
	if not session then return end;
	local log = session.log or module._log;
	local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
	if not muc_x then return end -- Not MUC related

	local room = jid_bare(stanza.attr.from);
	local joined = stanza.attr.type;
	if joined == nil then
		joined = true;
	elseif joined == "unavailable" then
		joined = nil;
	else
		-- Ignore errors and whatever
		return;
	end

	-- Check for status code 100, meaning it's their own reflected presence
	for status in muc_x:childtags("status") do
		log("debug", "Status code %d", status.attr.code);
		if status.attr.code == "110" then
			log("debug", "%s room %s", joined and "Joined" or "Left", room);
			local rooms = session.rooms_joined;
			if not rooms then
				session.rooms_joined = { [room] = joined };
			else
				rooms[room] = joined;
			end
			return;
		end
	end
end);

-- TODO Check session.directed for outgoing presence?