changeset 1490:b06b5ac5714b

mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
author Kim Alvefur <zash@zash.se>
date Sun, 17 Aug 2014 23:10:19 +0200 (2014-08-17)
parents 95f10fb7f60e
children e7294423512f
files mod_filter_chatstates/mod_filter_chatstates.lua
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_filter_chatstates/mod_filter_chatstates.lua	Sun Aug 17 23:10:19 2014 +0200
@@ -0,0 +1,29 @@
+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);