Push notifications: switch to serviceWorkerRegistration.showNotification()

merge-requests/813/head
Alex Gleason 2021-10-21 17:09:02 -05:00
rodzic 260f5b5057
commit f79d4a3330
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -102,16 +102,17 @@ export function updateNotificationsQueue(notification, intlMessages, intlLocale,
// Desktop notifications
try {
if (typeof window.Notification !== 'undefined' && showAlert && !filtered) {
if (showAlert && !filtered) {
const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : unescapeHTML(notification.status ? notification.status.content : '');
const notify = new Notification(title, { body, icon: notification.account.avatar, tag: notification.id });
notify.addEventListener('click', () => {
window.focus();
notify.close();
});
navigator.serviceWorker.ready.then(serviceWorkerRegistration => {
serviceWorkerRegistration.showNotification(title, {
body,
icon: notification.account.avatar,
tag: notification.id,
});
}).catch(console.error);
}
} catch(e) {
console.warn(e);