annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local filters = require "util.filters";
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local st = require "util.stanza";
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
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)
Matthew Wild <mwild1@gmail.com>
parents: 1490
diff changeset
4 local dummy_stanza_mt = setmetatable({ __tostring = function () return ""; end }, { __index = st.stanza_mt });
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)
Matthew Wild <mwild1@gmail.com>
parents: 1490
diff changeset
5 local dummy_stanza = setmetatable(st.stanza(), dummy_stanza_mt);
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)
Matthew Wild <mwild1@gmail.com>
parents: 1490
diff changeset
6
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 module:depends("csi");
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local function filter_chatstates(stanza)
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 if stanza.name == "message" then
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 stanza = st.clone(stanza);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 stanza:maptags(function (tag)
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
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)
Matthew Wild <mwild1@gmail.com>
parents: 1490
diff changeset
14 return tag;
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 if #stanza.tags == 0 then
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)
Matthew Wild <mwild1@gmail.com>
parents: 1490
diff changeset
18 return dummy_stanza;
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 end
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 return stanza;
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 module:hook("csi-client-inactive", function (event)
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local session = event.origin;
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 filters.add_filter(session, "stanzas/out", filter_chatstates);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 module:hook("csi-client-active", function (event)
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 local session = event.origin;
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 filters.remove_filter(session, "stanzas/out", filter_chatstates);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end);