Mercurial > prosody-modules
annotate mod_throttle_presence/mod_throttle_presence.lua @ 6258:06fbbd45ba75
mod_cloud_notify: Readme: fix links and labels that were removed in the last commit
diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md
--- a/mod_cloud_notify/README.md
+++ b/mod_cloud_notify/README.md
@@ -1,3 +1,9 @@
+----
+-labels:
+-- 'Stage-Beta'
+-summary: 'XEP-0357: Cloud push notifications'
+----
+
# Introduction
This module enables support for sending "push notifications" to clients
@@ -32,15 +38,15 @@ notification to your device. When your d
it will display it or wake up the app so it can connect to XMPP and
receive any pending messages.
-This protocol is described for developers in \[XEP-0357: Push
-Notifications\].
+This protocol is described for developers in [XEP-0357: Push
+Notifications].
-For this module to work reliably, you must have \[mod_smacks\],
-\[mod_mam\] and \[mod_carbons\] also enabled on your server.
+For this module to work reliably, you must have [mod_smacks],
+[mod_mam] and [mod_carbons] also enabled on your server.
Some clients, notably Siskin and Snikket iOS need some additional
extensions that are not currently defined in a standard XEP. To support
-these clients, see \[mod_cloud_notify_extensions\].
+these clients, see [mod_cloud_notify_extensions].
# Configuration
@@ -58,18 +64,18 @@ these clients, see \[mod_cloud_notify_ex
# Internal design notes
App servers are notified about offline messages, messages stored by
-\[mod_mam\] or messages waiting in the smacks queue. The business rules
+[mod_mam] or messages waiting in the smacks queue. The business rules
outlined
[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html)
are all honored[^2].
-To cooperate with \[mod_smacks\] this module consumes some events:
+To cooperate with [mod_smacks] this module consumes some events:
`smacks-ack-delayed`, `smacks-hibernation-start` and
`smacks-hibernation-end`. These events allow this module to send out
notifications for messages received while the session is hibernated by
-\[mod_smacks\] or even when smacks acknowledgements for messages are
+[mod_smacks] or even when smacks acknowledgements for messages are
delayed by a certain amount of seconds configurable with the
-\[mod_smacks\] setting `smacks_max_ack_delay`.
+[mod_smacks] setting `smacks_max_ack_delay`.
The `smacks_max_ack_delay` setting allows to send out notifications to
clients which aren't already in smacks hibernation state (because the
| author | Menel <menel@snikket.de> |
|---|---|
| date | Fri, 13 Jun 2025 10:44:37 +0200 |
| parents | 552faee596b7 |
| children |
| rev | line source |
|---|---|
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
1 local filters = require "util.filters"; |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
2 local st = require "util.stanza"; |
|
162
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
4 module:depends("csi"); |
|
162
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
6 local function presence_filter(stanza, session) |
|
1867
34468d3bfcac
mod_throttle_presence: Skip past things that are not stanza objects
Kim Alvefur <zash@zash.se>
parents:
1504
diff
changeset
|
7 if getmetatable(stanza) ~= st.stanza_mt then |
|
34468d3bfcac
mod_throttle_presence: Skip past things that are not stanza objects
Kim Alvefur <zash@zash.se>
parents:
1504
diff
changeset
|
8 return stanza; -- Things we don't want to touch |
|
34468d3bfcac
mod_throttle_presence: Skip past things that are not stanza objects
Kim Alvefur <zash@zash.se>
parents:
1504
diff
changeset
|
9 end |
|
1504
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
10 if stanza._flush then |
|
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
11 stanza._flush = nil; |
|
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
12 return stanza; |
|
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
13 end |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
14 local buffer = session.presence_buffer; |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
15 local from = stanza.attr.from; |
|
1925
552faee596b7
mod_throttle_presence: Switch if-else statement around to improve readability
Kim Alvefur <zash@zash.se>
parents:
1867
diff
changeset
|
16 if stanza.name == "presence" and (stanza.attr.type == nil or stanza.attr.type == "unavailable") then |
|
552faee596b7
mod_throttle_presence: Switch if-else statement around to improve readability
Kim Alvefur <zash@zash.se>
parents:
1867
diff
changeset
|
17 module:log("debug", "Buffering presence stanza from %s to %s", stanza.attr.from, session.full_jid); |
|
552faee596b7
mod_throttle_presence: Switch if-else statement around to improve readability
Kim Alvefur <zash@zash.se>
parents:
1867
diff
changeset
|
18 buffer[stanza.attr.from] = st.clone(stanza); |
|
552faee596b7
mod_throttle_presence: Switch if-else statement around to improve readability
Kim Alvefur <zash@zash.se>
parents:
1867
diff
changeset
|
19 return nil; -- Drop this stanza (we've stored it for later) |
|
552faee596b7
mod_throttle_presence: Switch if-else statement around to improve readability
Kim Alvefur <zash@zash.se>
parents:
1867
diff
changeset
|
20 else |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
21 local cached_presence = buffer[stanza.attr.from]; |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
22 if cached_presence then |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
23 module:log("debug", "Important stanza for %s from %s, flushing presence", session.full_jid, from); |
|
1504
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
24 stanza._flush = true; |
|
b8164f18142a
mod_throttle_presence: Make sure flushed stanzas get through the filter
Kim Alvefur <zash@zash.se>
parents:
1489
diff
changeset
|
25 cached_presence._flush = true; |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
26 session.send(cached_presence); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
27 buffer[stanza.attr.from] = nil; |
|
162
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
|
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
30 return stanza; |
|
162
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
|
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
33 local function throttle_session(event) |
|
1488
ba97f9be4f76
mod_throttle_presence: Fix traceback (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
1485
diff
changeset
|
34 local session = event.origin; |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
35 if session.presence_buffer then return; end |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
36 module:log("debug", "Suppressing presence updates to %s", session.full_jid); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
37 session.presence_buffer = {}; |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
38 filters.add_filter(session, "stanzas/out", presence_filter); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
39 end |
|
162
fe9c4daee076
mod_throttle_presence: Buffer up presence for up to flush_presence_seconds and send latest presence stanzas for each contact at once
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
41 local function restore_session(event) |
|
1488
ba97f9be4f76
mod_throttle_presence: Fix traceback (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
1485
diff
changeset
|
42 local session = event.origin; |
|
1485
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
43 if not session.presence_buffer then return; end |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
44 filters.remove_filter(session, "stanzas/out", presence_filter); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
45 module:log("debug", "Flushing buffer for %s", session.full_jid); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
46 for jid, presence in pairs(session.presence_buffer) do |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
47 session.send(presence); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
48 end |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
49 session.presence_buffer = nil; |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
50 end |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
51 |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
52 module:hook("csi-client-inactive", throttle_session); |
|
d8c50448d0e7
mod_throttle_presence: Remove timer support, depend on mod_csi to enable/disable. Untested, but the previous version was definitely broken anyway.
Matthew Wild <mwild1@gmail.com>
parents:
162
diff
changeset
|
53 module:hook("csi-client-active", restore_session); |
