modify logic behind push notification subscriptions
This commit is contained in:
parent
a91821933f
commit
5aec0faa2c
1 changed files with 18 additions and 18 deletions
|
|
@ -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}`)
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue