annotate mod_mam_adhoc/mod_mam_adhoc.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 27b41ee61601
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:depends"adhoc";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local dataforms_new = require "util.dataforms".new;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid_split = require "util.jid".split;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local t_insert = table.insert;
1115
91d210b6106a mod_mam_adhoc: Use mod_mam/mamprefs.lib
Kim Alvefur <zash@zash.se>
parents: 739
diff changeset
5 local prefs = module:require"mod_mam/mamprefs";
91d210b6106a mod_mam_adhoc: Use mod_mam/mamprefs.lib
Kim Alvefur <zash@zash.se>
parents: 739
diff changeset
6 local set_prefs, get_prefs = prefs.set, prefs.get;
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local mam_prefs_form = dataforms_new{
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 title = "Archive preferences";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 --instructions = "";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 name = "default",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 label = "Default storage policy",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 type = "list-single",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 value = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 { value = "always", label = "Always" },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 { value = "never", label = "Never", default = true},
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 { value = "roster", label = "Roster" },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 name = "always",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 label = "Always store messages to/from",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 type = "jid-multi"
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 name = "never",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 label = "Never store messages to/from",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 type = "jid-multi"
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local host = module.host;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 local default_attrs = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 always = true, [true] = "always",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 never = false, [false] = "never",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 roster = "roster",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 }
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local function mam_prefs_handler(self, data, state)
1147
27b41ee61601 mod_mam_adhoc: Use the new adhoc permission level for local users
Kim Alvefur <zash@zash.se>
parents: 1115
diff changeset
42 local username = jid_split(data.from);
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 if state then -- the second return value
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 if data.action == "cancel" then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 return { status = "canceled" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 local fields = mam_prefs_form:data(data.form);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local default, always, never = fields.default, fields.always, fields.never;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 local prefs = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if default then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 prefs[false] = default_attrs[default];
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 if always then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 for i=1,#always do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 prefs[always[i]] = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 if never then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 for i=1,#never do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 prefs[never[i]] = false;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 set_prefs(username, prefs);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 return { status = "completed" }
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 else -- No state, send the form.
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 local prefs = get_prefs(username);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 local values = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 default = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 { value = "always", label = "Always" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 { value = "never", label = "Never" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 { value = "roster", label = "Roster" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 always = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 never = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 for jid, p in pairs(prefs) do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 if jid then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 t_insert(values[p and "always" or "never"], jid);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 elseif p == true then -- Yes, this is ugly. FIXME later.
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 values.default[1].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 elseif p == false then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 values.default[2].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 elseif p == "roster" then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 values.default[3].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return { status = "executing", actions = { "complete" }, form = { layout = mam_prefs_form, values = values } }, true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96
1147
27b41ee61601 mod_mam_adhoc: Use the new adhoc permission level for local users
Kim Alvefur <zash@zash.se>
parents: 1115
diff changeset
97 module:provides("adhoc", module:require"adhoc".new("Archive settings", "urn:xmpp:mam#configure", mam_prefs_handler, "local_user"));