comparison mod_filter_chatstates/mod_filter_chatstates.lua @ 1866:58d96960ba8b

mod_filter_chatstates: Break out maptags filter into a stateless function
author Kim Alvefur <zash@zash.se>
date Mon, 21 Sep 2015 23:44:55 +0200
parents 23b3c8e294d2
children d6e673f98572
comparison
equal deleted inserted replaced
1865:db8b256f51ff 1866:58d96960ba8b
1 local filters = require "util.filters"; 1 local filters = require "util.filters";
2 local st = require "util.stanza"; 2 local st = require "util.stanza";
3 3
4 module:depends("csi"); 4 module:depends("csi");
5 5
6 local function chatstate_tag_filter(tag)
7 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
8 return tag;
9 end
10 end
11
6 local function filter_chatstates(stanza) 12 local function filter_chatstates(stanza)
7 if stanza.name == "message" then 13 if stanza.name == "message" then
8 stanza = st.clone(stanza); 14 stanza = st.clone(stanza);
9 stanza:maptags(function (tag) 15 stanza:maptags(chatstate_tag_filter);
10 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
11 return tag
12 end
13 end);
14 if #stanza.tags == 0 then 16 if #stanza.tags == 0 then
15 return ""; 17 return "";
16 end 18 end
17 end 19 end
18 return stanza; 20 return stanza;