DEV: Return meaningful values from desktop noti enable/disable fns (#26061)

This commit is contained in:
Mark VanLandingham 2024-03-06 11:31:42 -06:00 committed by GitHub
parent 5d90332cfc
commit 4e80ad0724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -84,8 +84,8 @@ export function subscribe(callback, applicationServerKey) {
return;
}
navigator.serviceWorker.ready.then((serviceWorkerRegistration) => {
serviceWorkerRegistration.pushManager
return navigator.serviceWorker.ready.then((serviceWorkerRegistration) => {
return serviceWorkerRegistration.pushManager
.subscribe({
userVisibleOnly: true,
applicationServerKey: new Uint8Array(applicationServerKey.split("|")), // eslint-disable-line no-undef
@ -95,10 +95,12 @@ export function subscribe(callback, applicationServerKey) {
if (callback) {
callback();
}
return true;
})
.catch((e) => {
// eslint-disable-next-line no-console
console.error(e);
return false;
});
});
}
@ -109,7 +111,7 @@ export function unsubscribe(user, callback) {
}
keyValueStore.setItem(userSubscriptionKey(user), "");
navigator.serviceWorker.ready.then((serviceWorkerRegistration) => {
return navigator.serviceWorker.ready.then((serviceWorkerRegistration) => {
serviceWorkerRegistration.pushManager
.getSubscription()
.then((subscription) => {
@ -132,5 +134,6 @@ export function unsubscribe(user, callback) {
if (callback) {
callback();
}
return true;
});
}

View File

@ -119,9 +119,10 @@ export default class DesktopNotificationsService extends Service {
disable() {
if (this.isEnabledDesktop) {
this.setNotificationsDisabled("disabled");
return true;
}
if (this.isEnabledPush) {
unsubscribePushNotification(this.currentUser, () => {
return unsubscribePushNotification(this.currentUser, () => {
this.setIsEnabledPush("");
});
}
@ -130,13 +131,14 @@ export default class DesktopNotificationsService extends Service {
@action
enable() {
if (this.isPushNotificationsPreferred) {
subscribePushNotification(() => {
return subscribePushNotification(() => {
this.setIsEnabledPush("subscribed");
}, this.siteSettings.vapid_public_key_bytes);
} else {
this.setNotificationsDisabled("");
Notification.requestPermission(() => {
return Notification.requestPermission((permission) => {
confirmNotification(this.siteSettings);
return permission === "granted";
});
}
}