modify logic behind push notification subscriptions

This commit is contained in:
Henry Jameson 2026-02-12 22:24:33 +02:00
commit 5aec0faa2c

View file

@ -41,7 +41,7 @@ function subscribePush(registration, isEnabled, vapidPublicKey) {
function unsubscribePush(registration) { function unsubscribePush(registration) {
return registration.pushManager.getSubscription().then((subscription) => { return registration.pushManager.getSubscription().then((subscription) => {
if (subscription === null) { if (subscription === null) {
return return Promise.resolve('No subscription')
} }
return subscription.unsubscribe() return subscription.unsubscribe()
}) })
@ -158,23 +158,23 @@ export function registerPushNotifications(
export function unregisterPushNotifications(token) { export function unregisterPushNotifications(token) {
if (isPushSupported()) { if (isPushSupported()) {
Promise.all([ getOrCreateServiceWorker()
deleteSubscriptionFromBackEnd(token), .then((registration) => {
getOrCreateServiceWorker() return unsubscribePush(registration).then((result) => [
.then((registration) => { registration,
return unsubscribePush(registration).then((result) => [ result,
registration, ])
result, })
]) .then(([, unsubResult]) => {
}) if (unsubResult === 'No subscription') return
.then(([, unsubResult]) => { if (!unsubResult) {
if (!unsubResult) { console.warn("Push subscription cancellation wasn't successful")
console.warn("Push subscription cancellation wasn't successful") }
} return deleteSubscriptionFromBackEnd(token)
}), })
]).catch((e) => .catch((e) => {
console.warn(`Failed to disable Web Push Notifications: ${e.message}`), console.warn(`Failed to disable Web Push Notifications: ${e.message}`)
) })
} }
} }