comparison mod_filter_chatstates/mod_filter_chatstates.lua @ 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
parents
children 02cd4a081db4
comparison
equal deleted inserted replaced
1489:95f10fb7f60e 1490:b06b5ac5714b
1 local filters = require "util.filters";
2 local st = require "util.stanza";
3
4 module:depends("csi");
5
6 local function filter_chatstates(stanza)
7 if stanza.name == "message" then
8 stanza = st.clone(stanza);
9 stanza:maptags(function (tag)
10 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
11 return tag
12 end
13 end);
14 if #stanza.tags == 0 then
15 return nil;
16 end
17 end
18 return stanza;
19 end
20
21 module:hook("csi-client-inactive", function (event)
22 local session = event.origin;
23 filters.add_filter(session, "stanzas/out", filter_chatstates);
24 end);
25
26 module:hook("csi-client-active", function (event)
27 local session = event.origin;
28 filters.remove_filter(session, "stanzas/out", filter_chatstates);
29 end);