fix: Disable push notifications (#11786)
# Pull Request Template ## Description Fixes [CW-4512](https://linear.app/chatwoot/issue/CW-4512/cant-turn-off-push-notification-toggle) https://github.com/chatwoot/chatwoot/issues/11760 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -75,10 +75,34 @@ export default {
|
||||
onRegistrationSuccess() {
|
||||
this.hasEnabledPushPermissions = true;
|
||||
},
|
||||
onRequestPermissions() {
|
||||
requestPushPermissions({
|
||||
onSuccess: this.onRegistrationSuccess,
|
||||
});
|
||||
onRequestPermissions(value) {
|
||||
if (value) {
|
||||
// Enable / re-enable push notifications
|
||||
requestPushPermissions({
|
||||
onSuccess: this.onRegistrationSuccess,
|
||||
});
|
||||
} else {
|
||||
// Disable push notifications
|
||||
this.disablePushPermissions();
|
||||
}
|
||||
},
|
||||
disablePushPermissions() {
|
||||
verifyServiceWorkerExistence(registration =>
|
||||
registration.pushManager
|
||||
.getSubscription()
|
||||
.then(subscription => {
|
||||
if (subscription) {
|
||||
return subscription.unsubscribe();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.finally(() => {
|
||||
this.hasEnabledPushPermissions = false;
|
||||
})
|
||||
.catch(() => {
|
||||
// error
|
||||
})
|
||||
);
|
||||
},
|
||||
getPushSubscription() {
|
||||
verifyServiceWorkerExistence(registration =>
|
||||
|
||||
Reference in New Issue
Block a user