Merge branch 'fix-push-notifications-mobile' into 'develop'

Push notifications: switch to serviceWorkerRegistration.showNotification()

See merge request soapbox-pub/soapbox-fe!813
This commit is contained in:
Alex Gleason 2021-10-21 22:10:57 +00:00
commit ee3621428c
1 changed files with 8 additions and 7 deletions

View File

@ -102,16 +102,17 @@ export function updateNotificationsQueue(notification, intlMessages, intlLocale,
// Desktop notifications // Desktop notifications
try { 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 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 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 }); navigator.serviceWorker.ready.then(serviceWorkerRegistration => {
serviceWorkerRegistration.showNotification(title, {
notify.addEventListener('click', () => { body,
window.focus(); icon: notification.account.avatar,
notify.close(); tag: notification.id,
}); });
}).catch(console.error);
} }
} catch(e) { } catch(e) {
console.warn(e); console.warn(e);