From b831914f7068f55ea7b43547257182c5896ad46a Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Thu, 28 Mar 2024 14:19:04 +1100 Subject: [PATCH] feat: update CallNotificaiton strings and enforce type safety --- .../notification-bubble/CallNotification.tsx | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ts/components/conversation/message/message-item/notification-bubble/CallNotification.tsx b/ts/components/conversation/message/message-item/notification-bubble/CallNotification.tsx index ea983a896..a3240401e 100644 --- a/ts/components/conversation/message/message-item/notification-bubble/CallNotification.tsx +++ b/ts/components/conversation/message/message-item/notification-bubble/CallNotification.tsx @@ -10,24 +10,24 @@ import { useSelectedDisplayNameInProfile, useSelectedNickname, } from '../../../../../state/selectors/selectedConversation'; -import { LocalizerKeys } from '../../../../../types/LocalizerKeys'; +import { LocalizerToken } from '../../../../../types/Localizer'; import { SessionIconType } from '../../../../icon'; import { ExpirableReadableMessage } from '../ExpirableReadableMessage'; import { NotificationBubble } from './NotificationBubble'; type StyleType = Record< CallNotificationType, - { notificationTextKey: LocalizerKeys; iconType: SessionIconType; iconColor: string } + { notificationTextKey: LocalizerToken; iconType: SessionIconType; iconColor: string } >; -const style: StyleType = { +const style = { 'missed-call': { - notificationTextKey: 'callMissed', + notificationTextKey: 'callsMissedCallFrom', iconType: 'callMissed', iconColor: 'var(--danger-color)', }, 'started-call': { - notificationTextKey: 'startedACall', + notificationTextKey: 'callsYouCalled', iconType: 'callOutgoing', iconColor: 'inherit', }, @@ -36,7 +36,7 @@ const style: StyleType = { iconType: 'callIncoming', iconColor: 'inherit', }, -}; +} satisfies StyleType; export const CallNotification = (props: PropsForCallNotification) => { const { messageId, notificationType } = props; @@ -49,12 +49,11 @@ export const CallNotification = (props: PropsForCallNotification) => { nickname || displayNameInProfile || (selectedConvoId && PubKey.shorten(selectedConvoId)); const styleItem = style[notificationType]; - const notificationText = window.i18n(styleItem.notificationTextKey, [ - displayName || window.i18n('unknown'), - ]); - if (!window.i18n(styleItem.notificationTextKey)) { - throw new Error(`invalid i18n key ${styleItem.notificationTextKey}`); - } + + const notificationText = window.i18n(styleItem.notificationTextKey, { + name: displayName ?? window.i18n('unknown'), + }); + const iconType = styleItem.iconType; const iconColor = styleItem.iconColor;