mod_filter_chatstates/mod_filter_chatstates.lua
author Kim Alvefur <zash@zash.se>
Mon, 24 Aug 2015 23:17:36 +0200
changeset 1788 1656d4fd71d0
parent 1771 ca48eea4785c
child 1833 23b3c8e294d2
permissions -rw-r--r--
mod_cloud_notify: Fix syntax errors and name

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

module:depends("csi");

local function filter_chatstates(stanza)
	if stanza.name == "message" then
		stanza = st.clone(stanza);
		stanza:maptags(function (tag)
			if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
				return tag
			end
		end);
		if #stanza.tags == 0 then
			return nil;
		end
	end
	return stanza;
end

module:hook("csi-client-inactive", function (event)
	local session = event.origin;
	filters.add_filter(session, "stanzas/out", filter_chatstates);
end);

module:hook("csi-client-active", function (event)
	local session = event.origin;
	filters.remove_filter(session, "stanzas/out", filter_chatstates);
end);