Annotate

mod_adhoc_dataforms_demo/mod_adhoc_dataforms_demo.lua @ 6301:fa45ae704b79

mod_cloud_notify: Update Readme 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,109 +1,106 @@ ---- -labels: -- 'Stage-Beta' -summary: 'XEP-0357: Cloud push notifications' ---- +# Introduction -Introduction -============ +This module enables support for sending "push notifications" to clients +that need it, typically those running on certain mobile devices. -This module enables support for sending "push notifications" to clients that -need it, typically those running on certain mobile devices. +As well as this module, your client must support push notifications (the +apps that need it generally do, of course) and the app developer's push +gateway must be reachable from your Prosody server (this happens over a +normal XMPP server-to-server 's2s' connection). -As well as this module, your client must support push notifications (the apps -that need it generally do, of course) and the app developer's push gateway -must be reachable from your Prosody server (this happens over a normal XMPP -server-to-server 's2s' connection). - -Details -======= +# Details Some platforms, notably Apple's iOS and many versions of Android, impose -limits that prevent applications from running or accessing the network in the -background. This makes it difficult or impossible for an XMPP application to -remain reliably connected to a server to receive messages. - -In order for messaging and other apps to receive notifications, the OS vendors -run proprietary servers that their OS maintains a permanent connection to in -the background. Then they provide APIs to application developers that allow -sending notifications to specific devices via those servers. +limits that prevent applications from running or accessing the network +in the background. This makes it difficult or impossible for an XMPP +application to remain reliably connected to a server to receive +messages. -When you connect to your server with an app that requires push notifications, -it will use this module to set up a "push registration". When you receive -a message but your device is not connected to the server, this module will -generate a notification and send it to the push gateway operated by your -application's developers). Their gateway will then connect to your device's -OS vendor and ask them to forward the notification to your device. When your -device receives the notification, it will display it or wake up the app so it -can connect to XMPP and receive any pending messages. +In order for messaging and other apps to receive notifications, the OS +vendors run proprietary servers that their OS maintains a permanent +connection to in the background. Then they provide APIs to application +developers that allow sending notifications to specific devices via +those servers. -This protocol is described for developers in [XEP-0357: Push Notifications]. +When you connect to your server with an app that requires push +notifications, it will use this module to set up a "push registration". +When you receive a message but your device is not connected to the +server, this module will generate a notification and send it to the push +gateway operated by your application's developers). Their gateway will +then connect to your device's OS vendor and ask them to forward the +notification to your device. When your device receives the notification, +it will display it or wake up the app so it can connect to XMPP and +receive any pending messages. -For this module to work reliably, you must have [mod_smacks], [mod_mam] and -[mod_carbons] also enabled on your server. +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. -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]. +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\]. -Configuration -============= +# Configuration - Option Default Description - ------------------------------------ ----------------- ------------------------------------------------------------------------------------------------------------------- - `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty - `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled - `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) - `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) - `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. - `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. + Option Default Description + -------------------------------------- ---------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty + `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled + `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) + `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) + `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. + `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. -(\*) There are privacy implications for enabling these options. +(\*) There are privacy implications for enabling these options.[^1] -Internal design notes -===================== +# 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 outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2]. +App servers are notified about offline messages, messages stored by +\[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: -`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 delayed by a certain amount of seconds -configurable with the [mod_smacks] setting `smacks_max_ack_delay`. +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 +delayed by a certain amount of seconds configurable with the +\[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 read timeout or -connection close didn't already happen) but also aren't responding to acknowledgement -request in a timely manner. This setting thus allows conversations to be smoother -under such circumstances. +The `smacks_max_ack_delay` setting allows to send out notifications to +clients which aren't already in smacks hibernation state (because the +read timeout or connection close didn't already happen) but also aren't +responding to acknowledgement request in a timely manner. This setting +thus allows conversations to be smoother under such circumstances. -The new event `cloud-notify-ping` can be used by any module to send out a cloud -notification to either all registered endpoints for the given user or only the endpoints -given in the event data. +The new event `cloud-notify-ping` can be used by any module to send out +a cloud notification to either all registered endpoints for the given +user or only the endpoints given in the event data. -The config setting `push_notification_important_body` can be used to specify an alternative -body text to send to the remote pubsub node if the stanza is encrypted or has a body. -This way the real contents of the message aren't revealed to the push appserver but it -can still see that the push is important. -This is used by Chatsecure on iOS to send out high priority pushes in those cases for example. +The config setting `push_notification_important_body` can be used to +specify an alternative body text to send to the remote pubsub node if +the stanza is encrypted or has a body. This way the real contents of the +message aren't revealed to the push appserver but it can still see that +the push is important. This is used by Chatsecure on iOS to send out +high priority pushes in those cases for example. -Compatibility -============= - -**Note:** This module should be used with Lua 5.2 and higher. Using it with -Lua 5.1 may cause push notifications to not be sent to some clients. +# Compatibility ------- ----------------------------------------------------------------------------- - trunk Works - 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua) ------- ----------------------------------------------------------------------------- +**Note:** This module should be used with Lua 5.2 and higher. Using it +with Lua 5.1 may cause push notifications to not be sent to some +clients. + ------- ----------------------------------------------------------------- + trunk Works as of 25-06-13 + 13 Works + 0.12 Works + ------- ----------------------------------------------------------------- -[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service -[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown) +[^1]: The service which is expected to forward notifications to + something like Google Cloud Messaging or Apple Notification Service + +[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:36:52 +0200
parent 4581:3e2e708fd18b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local dataforms = require "util.dataforms";
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local adhoc_util = require "util.adhoc";
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local serialization = require "util.serialization";
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local adhoc_new = module:require "adhoc".new;
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- Dataform borrowed from Prosodys busted test for util.dataforms
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local form = dataforms.new({
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 title = "form-title",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 instructions = "form-instructions",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 type = "hidden",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 name = "FORM_TYPE",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 value = "xmpp:prosody.im/spec/util.dataforms#1",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 };
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 type = "fixed",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 label = "fixed-label",
3556
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
19 name = "fixed-field#1",
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 value = "fixed-value",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 type = "hidden",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 label = "hidden-label",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 name = "hidden-field",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 value = "hidden-value",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 {
3556
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
29 type = "text-single",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
30 label = "text-single-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
31 name = "text-single-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
32 value = "text-single-value",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
33 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
34 {
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
35 type = "text-multi",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
36 label = "text-multi-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
37 name = "text-multi-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
38 value = "text\nmulti\nvalue",
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 {
3556
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
41 type = "text-private",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
42 label = "text-private-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
43 name = "text-private-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
44 value = "text-private-value",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
45 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
46 {
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
47 type = "boolean",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
48 label = "boolean-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
49 name = "boolean-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
50 value = true,
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
51 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
52 {
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
53 type = "fixed",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
54 label = "fixed-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
55 name = "fixed-field#2",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
56 value = "fixed-value",
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 type = "list-multi",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 label = "list-multi-label",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 name = "list-multi-field",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 value = {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 "list-multi-option-value#1",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 "list-multi-option-value#3",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 options = {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 label = "list-multi-option-label#1",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 value = "list-multi-option-value#1",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 default = true,
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 label = "list-multi-option-label#2",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 value = "list-multi-option-value#2",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 default = false,
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 label = "list-multi-option-label#3",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 value = "list-multi-option-value#3",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 default = true,
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 }
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 {
3556
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
85 type = "jid-single",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
86 label = "jid-single-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
87 name = "jid-single-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
88 value = "jid@single/value",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
89 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
90 {
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
91 type = "jid-multi",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
92 label = "jid-multi-label",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
93 name = "jid-multi-field",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
94 value = {
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
95 "jid@multi/value#1",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
96 "jid@multi/value#2",
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
97 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
98 },
0d97cde1c7b0 mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents: 3555
diff changeset
99 {
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 type = "list-single",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 label = "list-single-label",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 name = "list-single-field",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 value = "list-single-value",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 options = {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 "list-single-value",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 "list-single-value#2",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 "list-single-value#3",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 }
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 },
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 })
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111
3213
85c8a8c33028 mod_adhoc_dataforms_demo: Silence warning about unused argument [luacheck]
Kim Alvefur <zash@zash.se>
parents: 3212
diff changeset
112 local function handler(fields, err, data) -- luacheck: ignore 212/data
3211
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 return {
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 status = "completed",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 info = "Data was:\n"
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 .. serialization.serialize(err or fields),
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 };
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 end
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 module:provides("adhoc",
2969ed764fe8 mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 adhoc_new("Dataforms Demo",
3557
54b4b020de4c mod_adhoc_dataforms_demo: Rename command node to reflect current module name
Kim Alvefur <zash@zash.se>
parents: 3556
diff changeset
122 "xmpp:zash.se/mod_adhoc_dataforms_demo#form",
3914
f5caacd475c4 mod_adhoc_dataforms_demo: Add the now required permission mode (#1482)
Kim Alvefur <zash@zash.se>
parents: 3558
diff changeset
123 adhoc_util.new_simple_form(form, handler), "any"));
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
124
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
125
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
126 local function multi_step_command(_, data, state)
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
127
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
128 if data.action == "cancel" then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
129 return { status = "canceled" };
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
130 elseif data.action == "complete" then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
131 return {
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
132 status = "completed",
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
133 info = "State was:\n"
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
134 .. serialization.serialize(state, { fatal = false }),
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
135 };
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
136 end
4050
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
137 if state and data.action == "execute" then
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
138 data.action = "next";
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
139 elseif not state and data.action == "next" then
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
140 -- Prevent jumping directly to step 2
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
141 return { status = "canceled", error = "Invalid action" };
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
142 end
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
143 state = state or { step = 1, forms = { } };
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
144
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
145 if data.action == "next" then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
146 state.step = state.step + 1;
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
147 elseif data.action == "prev" then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
148 state.step = math.max(state.step - 1, 1);
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
149 end
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
150
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
151 local current_form = state.forms[state.step]
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
152 if not current_form then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
153 current_form = {
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
154 title = string.format("Step %d", state.step);
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
155 instructions = state.step == 1 and "Here's a form." or "Here's another form.";
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
156 };
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
157 local already_selected = {};
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
158 for _ = 1, math.random(1, 5) do
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
159 local random
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
160 repeat
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
161 random = math.random(2, #form);
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
162 until not already_selected[random]
4049
78f1de5301fc mod_adhoc_dataforms_demo: Fix duplicate field prevention
Kim Alvefur <zash@zash.se>
parents: 4045
diff changeset
163 already_selected[random] = true;
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
164 table.insert(current_form, form[random]);
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
165 end
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
166 state.forms[state.step] = dataforms.new(current_form);
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
167 end
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
168
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
169 local next_step = {
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
170 status = "executing",
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
171 form = current_form,
4050
1eb2b9483081 mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents: 4049
diff changeset
172 default = "next",
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
173 actions = {
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
174 "next", "complete"
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
175 },
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
176 };
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
177 if state.step > 1 then
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
178 table.insert(next_step.actions, 1, "prev");
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
179 end
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
180 return next_step, state;
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
181 end
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
182
4581
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
183 local permission = "any";
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
184 if not module.send_iq then -- hacky attempt at detecting 0.11 or earlier
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
185 permission = "user";
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
186 end
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
187
4045
4fc6cf528a9a mod_adhoc_dataforms_demo: Ensure mod_adhoc is loaded
Kim Alvefur <zash@zash.se>
parents: 3914
diff changeset
188 module:depends("adhoc");
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
189 module:provides("adhoc",
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
190 adhoc_new("Multi-step command demo",
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
191 "xmpp:zash.se/mod_adhoc_dataforms_demo#multi",
4581
3e2e708fd18b mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents: 4050
diff changeset
192 multi_step_command, permission));
3558
22587eb2d87c mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents: 3557
diff changeset
193