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() {
|
onRegistrationSuccess() {
|
||||||
this.hasEnabledPushPermissions = true;
|
this.hasEnabledPushPermissions = true;
|
||||||
},
|
},
|
||||||
onRequestPermissions() {
|
onRequestPermissions(value) {
|
||||||
requestPushPermissions({
|
if (value) {
|
||||||
onSuccess: this.onRegistrationSuccess,
|
// 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() {
|
getPushSubscription() {
|
||||||
verifyServiceWorkerExistence(registration =>
|
verifyServiceWorkerExistence(registration =>
|
||||||
|
|||||||
Reference in New Issue
Block a user