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,8 +158,6 @@ export function registerPushNotifications(
export function unregisterPushNotifications(token) { export function unregisterPushNotifications(token) {
if (isPushSupported()) { if (isPushSupported()) {
Promise.all([
deleteSubscriptionFromBackEnd(token),
getOrCreateServiceWorker() getOrCreateServiceWorker()
.then((registration) => { .then((registration) => {
return unsubscribePush(registration).then((result) => [ return unsubscribePush(registration).then((result) => [
@ -168,13 +166,15 @@ export function unregisterPushNotifications(token) {
]) ])
}) })
.then(([, unsubResult]) => { .then(([, unsubResult]) => {
if (unsubResult === 'No subscription') return
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) => })
console.warn(`Failed to disable Web Push Notifications: ${e.message}`), .catch((e) => {
) console.warn(`Failed to disable Web Push Notifications: ${e.message}`)
})
} }
} }