Comparison

mod_push2/mod_push2.lua @ 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
parent 6186:1cf563a94620
child 6212:051974b4c900
comparison
equal deleted inserted replaced
6189:72b7e0ca71ab 6190:aa240145aa22
103 origin.send(st.reply(stanza)) 103 origin.send(st.reply(stanza))
104 end 104 end
105 return true 105 return true
106 end 106 end
107 module:hook("iq-set/self/"..xmlns_push..":enable", push_enable) 107 module:hook("iq-set/self/"..xmlns_push..":enable", push_enable)
108
109 local function push_disable(event)
110 local origin, stanza = event.origin, event.stanza;
111 local enable = stanza.tags[1];
112 origin.log("debug", "Attempting to disable push notifications")
113 -- Tie registration to client, via client_id with sasl2 or else fallback to resource
114 local registration_id = origin.client_id or origin.resource
115 -- TODO: can we move to keyval+ on trunk?
116 local registrations = push2_registrations:get(origin.username) or {}
117 registrations[registration_id] = nil
118 if not push2_registrations:set(origin.username, registrations) then
119 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
120 else
121 origin.push_registration_id = nil
122 origin.push_registration = nil
123 origin.first_hibernated_push = nil
124 origin.log("info", "Push notifications disabled for %s (%s)", tostring(stanza.attr.from), registration_id)
125 origin.send(st.reply(stanza))
126 end
127 return true
128 end
129 module:hook("iq-set/self/"..xmlns_push..":disable", push_disable)
108 130
109 -- urgent stanzas should be delivered without delay 131 -- urgent stanzas should be delivered without delay
110 local function is_voip(stanza) 132 local function is_voip(stanza)
111 if stanza.name == "message" then 133 if stanza.name == "message" then
112 if stanza:get_child("propose", "urn:xmpp:jingle-message:0") then 134 if stanza:get_child("propose", "urn:xmpp:jingle-message:0") then