fix(service-worker): fix SwPush.unsubscribe()
(#24162)
Fixes #24095 PR Close #24162
This commit is contained in:
parent
5b823dedcc
commit
ea2987c7af
@ -73,21 +73,22 @@ export class SwPush {
|
|||||||
if (!this.sw.isEnabled) {
|
if (!this.sw.isEnabled) {
|
||||||
return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
|
return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
|
||||||
}
|
}
|
||||||
const unsubscribe = this.subscription.pipe(switchMap((sub: PushSubscription | null) => {
|
|
||||||
if (sub !== null) {
|
const doUnsubscribe = (sub: PushSubscription | null) => {
|
||||||
return sub.unsubscribe().then(success => {
|
if (sub === null) {
|
||||||
if (success) {
|
|
||||||
this.subscriptionChanges.next(null);
|
|
||||||
return undefined;
|
|
||||||
} else {
|
|
||||||
throw new Error('Unsubscribe failed!');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw new Error('Not subscribed to push notifications.');
|
throw new Error('Not subscribed to push notifications.');
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
return unsubscribe.pipe(take(1)).toPromise();
|
return sub.unsubscribe().then(success => {
|
||||||
|
if (!success) {
|
||||||
|
throw new Error('Unsubscribe failed!');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.subscriptionChanges.next(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.subscription.pipe(take(1), switchMap(doUnsubscribe)).toPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
private decodeBase64(input: string): string { return atob(input); }
|
private decodeBase64(input: string): string { return atob(input); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user