diff --git a/ts/components/settings/SessionNotificationGroupSettings.tsx b/ts/components/settings/SessionNotificationGroupSettings.tsx index ef21fe1ed..354fb3340 100644 --- a/ts/components/settings/SessionNotificationGroupSettings.tsx +++ b/ts/components/settings/SessionNotificationGroupSettings.tsx @@ -60,20 +60,17 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | if (!notificationsAreEnabled) { return; } - Notifications.addNotification( - { - conversationId: `preview-notification-${Date.now()}`, - message: - items.find(m => m.value === initialNotificationEnabled)?.label || - window?.i18n?.('messageBody') || - 'Message body', - title: window.i18n('notificationPreview'), - iconUrl: null, - isExpiringMessage: false, - messageSentAt: Date.now(), - }, - true - ); + Notifications.addPreviewNotification({ + conversationId: `preview-notification-${Date.now()}`, + message: + items.find(m => m.value === initialNotificationEnabled)?.label || + window?.i18n?.('messageBody') || + 'Message body', + title: window.i18n('notificationPreview'), + iconUrl: null, + isExpiringMessage: false, + messageSentAt: Date.now(), + }); }; return ( diff --git a/ts/util/notifications.ts b/ts/util/notifications.ts index dfed584d4..8950cf1f5 100644 --- a/ts/util/notifications.ts +++ b/ts/util/notifications.ts @@ -77,7 +77,7 @@ function disable() { * * @param forceRefresh Should only be set when the user triggers a test notification from the settings */ -function addNotification(notif: SessionNotification, forceRefresh = false) { +function addNotification(notif: SessionNotification) { const alreadyThere = currentNotifications.find( n => n.conversationId === notif.conversationId && n.messageId === notif.messageId ); @@ -86,11 +86,15 @@ function addNotification(notif: SessionNotification, forceRefresh = false) { return; } currentNotifications.push(notif); - if (forceRefresh) { - update(true); - } else { - debouncedUpdate(); - } + debouncedUpdate(); +} + +/** + * Special case when we want to display a preview of what notifications looks like + */ +function addPreviewNotification(notif: SessionNotification) { + currentNotifications.push(notif); + update(true); } function clearByConversationID(convoId: string) { @@ -251,6 +255,7 @@ function onRemove() { export const Notifications = { addNotification, + addPreviewNotification, disable, enable, clear,