Changeset

6190:aa240145aa22

mod_push2: support for disabling push notifications For example when logging out
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Wed, 05 Feb 2025 11:04:15 -0500
parents 6189:72b7e0ca71ab
children 6191:94399ad6b5ab
files mod_push2/mod_push2.lua mod_push2/push2.md
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_push2/mod_push2.lua	Tue Feb 04 23:40:33 2025 +0100
+++ b/mod_push2/mod_push2.lua	Wed Feb 05 11:04:15 2025 -0500
@@ -106,6 +106,28 @@
 end
 module:hook("iq-set/self/"..xmlns_push..":enable", push_enable)
 
+local function push_disable(event)
+	local origin, stanza = event.origin, event.stanza;
+	local enable = stanza.tags[1];
+	origin.log("debug", "Attempting to disable push notifications")
+	-- Tie registration to client, via client_id with sasl2 or else fallback to resource
+	local registration_id = origin.client_id or origin.resource
+	-- TODO: can we move to keyval+ on trunk?
+	local registrations = push2_registrations:get(origin.username) or {}
+	registrations[registration_id] = nil
+	if not push2_registrations:set(origin.username, registrations) then
+		origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
+	else
+		origin.push_registration_id = nil
+		origin.push_registration = nil
+		origin.first_hibernated_push = nil
+		origin.log("info", "Push notifications disabled for %s (%s)", tostring(stanza.attr.from), registration_id)
+		origin.send(st.reply(stanza))
+	end
+	return true
+end
+module:hook("iq-set/self/"..xmlns_push..":disable", push_disable)
+
 -- urgent stanzas should be delivered without delay
 local function is_voip(stanza)
 	if stanza.name == "message" then
--- a/mod_push2/push2.md	Tue Feb 04 23:40:33 2025 +0100
+++ b/mod_push2/push2.md	Wed Feb 05 11:04:15 2025 -0500
@@ -129,6 +129,12 @@
 </iq>
 ```
 
+## Client disables future pushes
+
+```xml
+<disable xmlns='urn:xmpp:push2:0' />
+```
+
 ## Push service interactions
 
 ### Transient delivery errors