From 9edfb1e902b0e463d130f726f92c399d66687318 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:31:39 +0530 Subject: [PATCH] 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 --- .../profile/NotificationPreferences.vue | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/settings/profile/NotificationPreferences.vue b/app/javascript/dashboard/routes/dashboard/settings/profile/NotificationPreferences.vue index 215b46923..6ab2b34d4 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/profile/NotificationPreferences.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/profile/NotificationPreferences.vue @@ -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 =>