Annotate

mod_roster_command/mod_roster_command.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 4326:f6fdefc5c6ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -----------------------------------------------------------
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- mod_roster_command: Manage rosters through prosodyctl
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- version 0.02
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 -----------------------------------------------------------
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- Copyright (C) 2011 Matthew Wild
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- Copyright (C) 2011 Adam Nielsen
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 -- This project is MIT/X11 licensed. Please see the
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 -- COPYING file in the source package for more information.
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 -----------------------------------------------------------
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
1947
634b42541f5b mod_roster_command: Attempt to update for compatibility with 0.10
Kim Alvefur <zash@zash.se>
parents: 1946
diff changeset
12 if module.host ~= "*" then
1946
1f263aaba83e mod_roster_command: Update link to new docs site
Kim Alvefur <zash@zash.se>
parents: 1565
diff changeset
13 module:log("error", "Do not load this module in Prosody, for correct usage see: https://modules.prosody.im/mod_roster_command.html");
492
f806c8a7f985 mod_roster_command: Fix traceback and log error message when loaded into Prosody (thanks epaulin)
Matthew Wild <mwild1@gmail.com>
parents: 453
diff changeset
14 return;
f806c8a7f985 mod_roster_command: Fix traceback and log error message when loaded into Prosody (thanks epaulin)
Matthew Wild <mwild1@gmail.com>
parents: 453
diff changeset
15 end
f806c8a7f985 mod_roster_command: Fix traceback and log error message when loaded into Prosody (thanks epaulin)
Matthew Wild <mwild1@gmail.com>
parents: 453
diff changeset
16
f806c8a7f985 mod_roster_command: Fix traceback and log error message when loaded into Prosody (thanks epaulin)
Matthew Wild <mwild1@gmail.com>
parents: 453
diff changeset
17
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 -- Workaround for lack of util.startup...
1948
2748aa8f36e0 mod_roster_command: Update workaround to perhaps work in 0.10
Kim Alvefur <zash@zash.se>
parents: 1947
diff changeset
19 local prosody = _G.prosody;
2748aa8f36e0 mod_roster_command: Update workaround to perhaps work in 0.10
Kim Alvefur <zash@zash.se>
parents: 1947
diff changeset
20 local hosts = prosody.hosts;
2748aa8f36e0 mod_roster_command: Update workaround to perhaps work in 0.10
Kim Alvefur <zash@zash.se>
parents: 1947
diff changeset
21 prosody.bare_sessions = prosody.bare_sessions or {};
2748aa8f36e0 mod_roster_command: Update workaround to perhaps work in 0.10
Kim Alvefur <zash@zash.se>
parents: 1947
diff changeset
22 _G.bare_sessions = _G.bare_sessions or prosody.bare_sessions;
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
1947
634b42541f5b mod_roster_command: Attempt to update for compatibility with 0.10
Kim Alvefur <zash@zash.se>
parents: 1946
diff changeset
24 local usermanager = require "core.usermanager";
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local rostermanager = require "core.rostermanager";
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 local storagemanager = require "core.storagemanager";
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local jid = require "util.jid";
1947
634b42541f5b mod_roster_command: Attempt to update for compatibility with 0.10
Kim Alvefur <zash@zash.se>
parents: 1946
diff changeset
28 local warn = require"util.prosodyctl".show_warning;
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 -- Make a *one-way* subscription. User will see when contact is online,
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 -- contact will not see when user is online.
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 function subscribe(user_jid, contact_jid)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local user_username, user_host = jid.split(user_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 local contact_username, contact_host = jid.split(contact_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 if not hosts[user_host] then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 warn("The host '%s' is not configured for this server.", user_host);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 return;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
1509
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
39 if hosts[user_host].users.name == "null" then
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
40 storagemanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
41 usermanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
42 end
4326
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
43 -- Update user's roster to say subscription request is pending. Bare hosts (e.g. components) don't have rosters.
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
44 if user_username ~= nil then
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
45 rostermanager.set_contact_pending_out(user_username, user_host, contact_jid);
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
46 end
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 if hosts[contact_host] then
1509
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
48 if contact_host ~= user_host and hosts[contact_host].users.name == "null" then
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 storagemanager.initialize_host(contact_host);
1508
f7cb287dd3c7 mod_roster_command: Also initialize usermanager
Kim Alvefur <zash@zash.se>
parents: 492
diff changeset
50 usermanager.initialize_host(contact_host);
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 -- Update contact's roster to say subscription request is pending...
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 rostermanager.set_contact_pending_in(contact_username, contact_host, user_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 -- Update contact's roster to say subscription request approved...
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 rostermanager.subscribed(contact_username, contact_host, user_jid);
4326
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
56 -- Update user's roster to say subscription request approved. Bare hosts (e.g. components) don't have rosters.
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
57 if user_username ~= nil then
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
58 rostermanager.process_inbound_subscription_approval(user_username, user_host, contact_jid);
f6fdefc5c6ac mod_roster_command: Fix subscription when the "user JID" is a bare domain.
Boris Grozev <boris@jitsi.org>
parents: 1948
diff changeset
59 end
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 -- Make a mutual subscription between jid1 and jid2. Each JID will see
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 -- when the other one is online.
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 function subscribe_both(jid1, jid2)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 subscribe(jid1, jid2);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 subscribe(jid2, jid1);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 -- Unsubscribes user from contact (not contact from user, if subscribed).
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 function unsubscribe(user_jid, contact_jid)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 local user_username, user_host = jid.split(user_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 local contact_username, contact_host = jid.split(contact_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 if not hosts[user_host] then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 warn("The host '%s' is not configured for this server.", user_host);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 return;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 end
1509
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
78 if hosts[user_host].users.name == "null" then
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
79 storagemanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
80 usermanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
81 end
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 -- Update user's roster to say subscription is cancelled...
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 rostermanager.unsubscribe(user_username, user_host, contact_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 if hosts[contact_host] then
1509
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
85 if contact_host ~= user_host and hosts[contact_host].users.name == "null" then
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 storagemanager.initialize_host(contact_host);
1508
f7cb287dd3c7 mod_roster_command: Also initialize usermanager
Kim Alvefur <zash@zash.se>
parents: 492
diff changeset
87 usermanager.initialize_host(contact_host);
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 -- Update contact's roster to say subscription is cancelled...
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 rostermanager.unsubscribed(contact_username, contact_host, user_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 -- Cancel any subscription in either direction.
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 function unsubscribe_both(jid1, jid2)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 unsubscribe(jid1, jid2);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 unsubscribe(jid2, jid1);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 -- Set the name shown and group used in the contact list
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 function rename(user_jid, contact_jid, contact_nick, contact_group)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 local user_username, user_host = jid.split(user_jid);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 if not hosts[user_host] then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 warn("The host '%s' is not configured for this server.", user_host);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 return;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 end
1509
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
107 if hosts[user_host].users.name == "null" then
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
108 storagemanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
109 usermanager.initialize_host(user_host);
01e37ce7532e mod_roster_command: Make sure hosts are only initialized once
Kim Alvefur <zash@zash.se>
parents: 1508
diff changeset
110 end
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 -- Load user's roster and find the contact
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 local roster = rostermanager.load_roster(user_username, user_host);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 local item = roster[contact_jid];
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 if item then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 if contact_nick then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 item.name = contact_nick;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 if contact_group then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 item.groups = {}; -- Remove from all current groups
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 item.groups[contact_group] = true;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 rostermanager.save_roster(user_username, user_host, roster);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
1565
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
127 function remove(user_jid, contact_jid)
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
128 unsubscribe_both(user_jid, contact_jid);
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
129 local user_username, user_host = jid.split(user_jid);
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
130 local roster = rostermanager.load_roster(user_username, user_host);
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
131 roster[contact_jid] = nil;
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
132 rostermanager.save_roster(user_username, user_host, roster);
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
133 end
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
134
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 function module.command(arg)
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 local command = arg[1];
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 if not command then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 warn("Valid subcommands: (un)subscribe(_both) | rename");
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 table.remove(arg, 1);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 if command == "subscribe" then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 subscribe(arg[1], arg[2]);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 elseif command == "subscribe_both" then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 subscribe_both(arg[1], arg[2]);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 elseif command == "unsubscribe" then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 unsubscribe(arg[1], arg[2]);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 elseif command == "unsubscribe_both" then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 unsubscribe_both(arg[1], arg[2]);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 return 0;
1565
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
154 elseif command == "remove" then
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
155 remove(arg[1], arg[2]);
f9cb09d451c7 mod_roster_command: Add 'remove' command
Kim Alvefur <zash@zash.se>
parents: 1509
diff changeset
156 return 0;
453
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 elseif command == "rename" then
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 rename(arg[1], arg[2], arg[3], arg[4]);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 else
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 warn("Unknown command: %s", command);
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 return 1;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 end
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 return 0;
1969310ea06a mod_roster_command: Manage rosters through prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end