annotate mod_filter_chatstates/mod_filter_chatstates.lua @ 4542:fb4a50bf60f1

mod_prometheus: Invoke stats collection if in 'manual' mode Since 10d13e0554f9 a special value for statistics_interval "manual" exists, where a module is expected to invoke processing in connection to collection of stats. This makes internal collection and exporting to Prometheus happens at the same time with no chance of timers getting out of sync.
author Kim Alvefur <zash@zash.se>
date Tue, 13 Apr 2021 23:53:53 +0200
parents d6e673f98572
children
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
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 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
5
1866
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
6 local function chatstate_tag_filter(tag)
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
7 if tag.attr.xmlns ~= "http://jabber.org/protocol/chatstates" then
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
8 return tag;
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
9 end
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
10 end
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
11
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 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
13 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
14 stanza = st.clone(stanza);
1866
58d96960ba8b mod_filter_chatstates: Break out maptags filter into a stateless function
Kim Alvefur <zash@zash.se>
parents: 1829
diff changeset
15 stanza:maptags(chatstate_tag_filter);
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 if #stanza.tags == 0 then
1868
d6e673f98572 mod_filter_chatstates: Revert filter-to-nothing hack
Kim Alvefur <zash@zash.se>
parents: 1866
diff changeset
17 return nil;
1490
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
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 return stanza;
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 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
24 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
25 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
26 end);
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
b06b5ac5714b mod_filter_chatstates: Removes chat states from messages to inactive (per CSI) sessions
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 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
29 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
30 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
31 end);