diff --git a/ts/components/settings/SessionNotificationGroupSettings.tsx b/ts/components/settings/SessionNotificationGroupSettings.tsx index 91744443e..86d2a854f 100644 --- a/ts/components/settings/SessionNotificationGroupSettings.tsx +++ b/ts/components/settings/SessionNotificationGroupSettings.tsx @@ -3,6 +3,7 @@ import React from 'react'; import useUpdate from 'react-use/lib/useUpdate'; import styled from 'styled-components'; import { SettingsKey } from '../../data/settings-key'; +import { Notifications } from '../../util/notifications'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; import { SessionRadioGroup } from '../basic/SessionRadioGroup'; import { SpacerLG } from '../basic/Text'; @@ -34,12 +35,6 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | const notificationsAreEnabled = initialItem && initialItem !== NOTIFICATION.OFF; - const onClickPreview = () => { - if (!notificationsAreEnabled) { - return; - } - }; - const items = [ { label: window.i18n('nameAndMessage'), @@ -55,6 +50,23 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | }, ]; + const onClickPreview = () => { + if (!notificationsAreEnabled) { + return; + } + Notifications.addNotification( + { + conversationId: `preview-notification-${Date.now()}`, + message: items.find(m => m.value === initialItem)?.label || 'Message body', + title: window.i18n('notificationPreview'), + iconUrl: null, + isExpiringMessage: false, + messageSentAt: Date.now(), + }, + true + ); + }; + return ( <> n.conversationId === notif.conversationId && n.messageId === notif.messageId ); @@ -79,7 +83,11 @@ function addNotification(notif: SessionNotification) { return; } currentNotifications.push(notif); - debouncedUpdate(); + if (forceRefresh) { + update(true); + } else { + debouncedUpdate(); + } } function clearByConversationID(convoId: string) { @@ -101,7 +109,7 @@ function clearByMessageId(messageId: string) { } } -function update() { +function update(forceRefresh = false) { if (lastNotificationDisplayed) { lastNotificationDisplayed.close(); lastNotificationDisplayed = null; @@ -115,7 +123,7 @@ function update() { const userSetting = getUserSetting(); const status = getStatus({ - isAppFocused, + isAppFocused: forceRefresh ? false : isAppFocused, isAudioNotificationEnabled, isAudioNotificationSupported: audioNotificationSupported, isEnabled, @@ -209,7 +217,7 @@ function update() { window.drawAttention(); lastNotificationDisplayed = new Notification(title || '', { body: window.platform === 'linux' ? filter(message) : message, - icon: iconUrl, + icon: iconUrl || undefined, silent: !status.shouldPlayNotificationSound, }); lastNotificationDisplayed.onclick = () => {