mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 03:29:31 +08:00
FIX: Bug in desktopNotifications service not allowing unsubscription (#26103)
This commit is contained in:
parent
4c7d58a883
commit
5f8cbb9d83
|
@ -16,6 +16,8 @@ import {
|
|||
} from "discourse/lib/push-notifications";
|
||||
|
||||
const keyValueStore = new KeyValueStore(context);
|
||||
const DISABLED = "disabled";
|
||||
const ENABLED = "enabled";
|
||||
|
||||
@disableImplicitInjections
|
||||
export default class DesktopNotificationsService extends Service {
|
||||
|
@ -28,9 +30,8 @@ export default class DesktopNotificationsService extends Service {
|
|||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.notificationsDisabled = keyValueStore.getItem(
|
||||
"notifications-disabled"
|
||||
);
|
||||
this.notificationsDisabled =
|
||||
keyValueStore.getItem("notifications-disabled") === DISABLED;
|
||||
this.isEnabledPush = this.currentUser
|
||||
? pushNotificationKeyValueStore.getItem(
|
||||
pushNotificationUserSubscriptionKey(this.currentUser)
|
||||
|
@ -48,9 +49,7 @@ export default class DesktopNotificationsService extends Service {
|
|||
|
||||
setNotificationsDisabled(value) {
|
||||
keyValueStore.setItem("notifications-disabled", value);
|
||||
this.notificationsDisabled = keyValueStore.getItem(
|
||||
"notifications-disabled"
|
||||
);
|
||||
this.notificationsDisabled = value === DISABLED;
|
||||
}
|
||||
|
||||
get isDeniedPermission() {
|
||||
|
@ -71,7 +70,7 @@ export default class DesktopNotificationsService extends Service {
|
|||
|
||||
get isEnabledDesktop() {
|
||||
if (this.isGrantedPermission) {
|
||||
return this.notificationsDisabled;
|
||||
return !this.notificationsDisabled;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -103,7 +102,7 @@ export default class DesktopNotificationsService extends Service {
|
|||
if (this.isPushNotificationsPreferred) {
|
||||
return this.isEnabledPush === "subscribed";
|
||||
} else {
|
||||
return this.notificationsDisabled === "";
|
||||
return !this.notificationsDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,16 +115,17 @@ export default class DesktopNotificationsService extends Service {
|
|||
}
|
||||
|
||||
@action
|
||||
disable() {
|
||||
async disable() {
|
||||
if (this.isEnabledDesktop) {
|
||||
this.setNotificationsDisabled("disabled");
|
||||
return true;
|
||||
this.setNotificationsDisabled(DISABLED);
|
||||
}
|
||||
if (this.isEnabledPush) {
|
||||
return unsubscribePushNotification(this.currentUser, () => {
|
||||
await unsubscribePushNotification(this.currentUser, () => {
|
||||
this.setIsEnabledPush("");
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -135,7 +135,7 @@ export default class DesktopNotificationsService extends Service {
|
|||
this.setIsEnabledPush("subscribed");
|
||||
}, this.siteSettings.vapid_public_key_bytes);
|
||||
} else {
|
||||
this.setNotificationsDisabled("");
|
||||
this.setNotificationsDisabled(ENABLED);
|
||||
return Notification.requestPermission((permission) => {
|
||||
confirmNotification(this.siteSettings);
|
||||
return permission === "granted";
|
||||
|
|
Loading…
Reference in New Issue
Block a user