diff --git a/src/client/sw/create-notification.ts b/src/client/sw/create-notification.ts index 77a7729621..e2d002c9fa 100644 --- a/src/client/sw/create-notification.ts +++ b/src/client/sw/create-notification.ts @@ -14,11 +14,15 @@ import { getAccountFromId } from '@client/scripts/get-account-from-id'; export async function createNotification(data: pushNotificationDataMap[K]) { const n = await composeNotification(data); - if (n) await self.registration.showNotification(...n); - else await createEmptyNotification(); + if (n) { + return self.registration.showNotification(...n); + } else { + console.error('Could not compose notification', data); + return createEmptyNotification(); + } } -async function composeNotification(data: pushNotificationDataMap[K]): Promise<[string, NotificationOptions] | null | undefined> { +async function composeNotification(data: pushNotificationDataMap[K]): Promise<[string, NotificationOptions] | null> { if (!swLang.i18n) swLang.fetchLocale(); const i18n = await swLang.i18n as I18n; const { t } = i18n; @@ -151,7 +155,7 @@ async function composeNotification(data }]; case 'groupInvited': - return [t('_notification.youWereInvitedToGroup', { userName: getUserName(data.body.group) }), { + return [t('_notification.youWereInvitedToGroup', { userName: getUserName(data.body.user) }), { body: data.body.invitation.group.name, data, actions: [ @@ -208,4 +212,18 @@ export async function createEmptyNotification() { tag: 'read_notification', } ); + + return new Promise(res => { + setTimeout(async () => { + for (const n of + [ + ...(await self.registration.getNotifications({ tag: 'user_visible_auto_notification' })), + ...(await self.registration.getNotifications({ tag: 'read_notification' })) + ] + ) { + n.close(); + } + res(); + }, 1000); + }) } diff --git a/src/client/sw/sw.ts b/src/client/sw/sw.ts index 03eb11353f..8024bb86ce 100644 --- a/src/client/sw/sw.ts +++ b/src/client/sw/sw.ts @@ -88,16 +88,6 @@ self.addEventListener('push', ev => { } createEmptyNotification(); - setTimeout(async () => { - for (const n of - [ - ...(await self.registration.getNotifications({ tag: 'user_visible_auto_notification' })), - ...(await self.registration.getNotifications({ tag: 'read_notification' })) - ] - ) { - n.close(); - } - }, 1000); })); }); //#endregion