Mercurial > prosody-modules
annotate mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua @ 6257: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 |
| parents | 791aa8072f58 |
| children |
| rev | line source |
|---|---|
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
1 local jid_split = require "util.jid".split; |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
2 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
3 local st = require "util.stanza"; |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
4 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
5 local mod_groups = module:depends("groups_internal") |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
6 local mod_pep = module:depends("pep") |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
7 |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
8 local XMLNS_BM2 = "urn:xmpp:bookmarks:1"; |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
9 local XMLNS_XEP0060 = "http://jabber.org/protocol/pubsub"; |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
10 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
11 local default_options = { |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
12 ["persist_items"] = true; |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
13 ["max_items"] = "max"; |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
14 ["send_last_published_item"] = "never"; |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
15 ["access_model"] = "whitelist"; |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
16 }; |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
17 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
18 local function get_current_bookmarks(jid, service) |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
19 local ok, items = service:get_items(XMLNS_BM2, jid) |
|
4863
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
20 if not ok then |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
21 if items == "item-not-found" then |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
22 return {}, nil; |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
23 else |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
24 return nil, items; |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
25 end |
|
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
26 end |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
27 return items or {}; |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
28 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
29 |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
30 local function update_bookmark(jid, service, room, bookmark) |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
31 local ok, err = service:publish(XMLNS_BM2, jid, room, bookmark, default_options); |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
32 if ok then |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
33 module:log("debug", "found existing matching bookmark, updated") |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
34 else |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
35 module:log("error", "failed to update bookmarks: %s", err) |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
36 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
37 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
38 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
39 local function find_matching_bookmark(storage, room) |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
40 return storage[room]; |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
41 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
42 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
43 local function inject_bookmark(jid, room, autojoin, name) |
|
5686
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
44 module:log("debug", "Injecting bookmark for %s into %s", room, jid); |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
45 local pep_service = mod_pep.get_pep_service(jid_split(jid)) |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
46 |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
47 local current, err = get_current_bookmarks(jid, pep_service); |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
48 if err then |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
49 module:log("error", "Could not retrieve existing bookmarks for %s: %s", jid, err); |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
50 return; |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
51 end |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
52 local found = find_matching_bookmark(current, room) |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
53 if found then |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
54 local existing = found:get_child("conference", XMLNS_BM2); |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
55 if autojoin ~= nil then |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
56 existing.attr.autojoin = autojoin and "true" or "false" |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
57 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
58 if name ~= nil then |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
59 -- do not change already configured names |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
60 if not existing.attr.name then |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
61 existing.attr.name = name |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
62 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
63 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
64 else |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
65 module:log("debug", "no existing bookmark found, adding new") |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
66 found = st.stanza("item", { xmlns = XMLNS_XEP0060; id = room }) |
|
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
67 :tag("conference", { xmlns = XMLNS_BM2; name = name; autojoin = autojoin and "true" or "false"; }) |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
68 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
69 |
|
4862
9a8a43d0faed
mod_groups_muc_bookmarks: fix typo/leftover from refactor
Jonas Schäfer <jonas@wielicki.name>
parents:
4861
diff
changeset
|
70 update_bookmark(jid, pep_service, room, found) |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
71 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
72 |
|
5823
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
73 local function remove_bookmark(jid, room) |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
74 local pep_service = mod_pep.get_pep_service(jid_split(jid)) |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
75 |
|
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
76 return pep_service:retract(XMLNS_BM2, jid, room, st.stanza("retract", { id = room })); |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
77 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
78 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
79 local function handle_user_added(event) |
|
5823
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
80 local group_info = event.group_info; |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
81 |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
82 local jid = event.user .. "@" .. event.host |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
83 |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
84 if group_info.muc_jid then |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
85 inject_bookmark(jid, group_info.muc_jid, true, group_info.name); |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
86 elseif group_info.mucs then |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
87 for _, chat in ipairs(mod_groups.get_group_chats(event.id)) do |
|
5826
791aa8072f58
mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents:
5823
diff
changeset
|
88 if not chat.deleted then |
|
791aa8072f58
mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents:
5823
diff
changeset
|
89 inject_bookmark(jid, chat.jid, true, chat.name); |
|
791aa8072f58
mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents:
5823
diff
changeset
|
90 end |
|
5823
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
91 end |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
92 else |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
93 module:log("debug", "ignoring user added event on group %s because it has no MUCs", event.id) |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
94 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
95 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
96 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
97 local function handle_user_removed(event) |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
98 -- Removing the bookmark is fine as the user just lost any privilege to |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
99 -- be in the MUC (as group MUCs are members-only). |
|
5823
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
100 local group_info = event.group_info; |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
101 local jid = event.user .. "@" .. event.host |
|
5823
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
102 |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
103 if group_info.muc_jid then |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
104 remove_bookmark(jid, event.group_info.muc_jid); |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
105 elseif group_info.mucs then |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
106 for _, muc_jid in ipairs(group_info.mucs) do |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
107 remove_bookmark(jid, muc_jid); |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
108 end |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
109 else |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
110 module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id) |
|
220502eb05aa
mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents:
5686
diff
changeset
|
111 end |
|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
112 end |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
113 |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
114 module:hook("group-user-added", handle_user_added) |
|
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
115 module:hook("group-user-removed", handle_user_removed) |
|
5686
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
116 |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
117 |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
118 local function handle_muc_added(event) |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
119 -- Add MUC to all members' bookmarks |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
120 module:log("info", "Adding new group chat to all member bookmarks..."); |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
121 local muc_jid, muc_name = event.muc.jid, event.muc.name; |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
122 for member_username in pairs(mod_groups.get_members(event.group_id)) do |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
123 local member_jid = member_username .. "@" .. module.host; |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
124 inject_bookmark(member_jid, muc_jid, true, muc_name); |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
125 end |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
126 end |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
127 |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
128 local function handle_muc_removed(event) |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
129 -- Remove MUC from all members' bookmarks |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
130 local muc_jid = event.muc.jid; |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
131 for member_username in ipairs(mod_groups.get_members(event.group_id)) do |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
132 local member_jid = member_username .. "@" .. module.host; |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
133 remove_bookmark(member_jid, muc_jid); |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
134 end |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
135 end |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
136 |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
137 module:hook("group-chat-added", handle_muc_added) |
|
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
138 module:hook("group-chat-removed", handle_muc_removed) |
