comparison mod_filter_chatstates/mod_filter_chatstates.lua @ 1494:02cd4a081db4

mod_filter_chatstates: Replace unwanted messages with a dummy stanza so that mod_message doesn't think delivery failed (and then generate an error reply)
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 Aug 2014 12:03:52 +0100
parents b06b5ac5714b
children ca48eea4785c
comparison
equal deleted inserted replaced
1493:d5e8758d391d 1494:02cd4a081db4
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
4 local dummy_stanza_mt = setmetatable({ __tostring = function () return ""; end }, { __index = st.stanza_mt });
5 local dummy_stanza = setmetatable(st.stanza(), dummy_stanza_mt);
3 6
4 module:depends("csi"); 7 module:depends("csi");
5 8
6 local function filter_chatstates(stanza) 9 local function filter_chatstates(stanza)
7 if stanza.name == "message" then 10 if stanza.name == "message" then
8 stanza = st.clone(stanza); 11 stanza = st.clone(stanza);
9 stanza:maptags(function (tag) 12 stanza:maptags(function (tag)
10 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then 13 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
11 return tag 14 return tag;
12 end 15 end
13 end); 16 end);
14 if #stanza.tags == 0 then 17 if #stanza.tags == 0 then
15 return nil; 18 return dummy_stanza;
16 end 19 end
17 end 20 end
18 return stanza; 21 return stanza;
19 end 22 end
20 23