Mercurial > prosody-modules
annotate mod_filter_chatstates/mod_filter_chatstates.lua @ 2181:f00cbfb812cd
mod_s2s_auth_dane: Attempt a new approach to async lookups that doesn't depend on connection pausing
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 26 May 2016 15:35:52 +0200 |
parents | d6e673f98572 |
children |
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); |