mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
DEV: Return meaningful values from desktop noti enable/disable fns (#26061)
This commit is contained in:
parent
5d90332cfc
commit
4e80ad0724
@ -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;
|
||||
});
|
||||
}
|
||||
|
@ -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";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user