feat: update CallNotificaiton strings and enforce type safety

pull/3206/head
Ryan Miller 1 year ago
parent 060a905b1f
commit b831914f70

@ -10,24 +10,24 @@ import {
useSelectedDisplayNameInProfile, useSelectedDisplayNameInProfile,
useSelectedNickname, useSelectedNickname,
} from '../../../../../state/selectors/selectedConversation'; } from '../../../../../state/selectors/selectedConversation';
import { LocalizerKeys } from '../../../../../types/LocalizerKeys'; import { LocalizerToken } from '../../../../../types/Localizer';
import { SessionIconType } from '../../../../icon'; import { SessionIconType } from '../../../../icon';
import { ExpirableReadableMessage } from '../ExpirableReadableMessage'; import { ExpirableReadableMessage } from '../ExpirableReadableMessage';
import { NotificationBubble } from './NotificationBubble'; import { NotificationBubble } from './NotificationBubble';
type StyleType = Record< type StyleType = Record<
CallNotificationType, CallNotificationType,
{ notificationTextKey: LocalizerKeys; iconType: SessionIconType; iconColor: string } { notificationTextKey: LocalizerToken; iconType: SessionIconType; iconColor: string }
>; >;
const style: StyleType = { const style = {
'missed-call': { 'missed-call': {
notificationTextKey: 'callMissed', notificationTextKey: 'callsMissedCallFrom',
iconType: 'callMissed', iconType: 'callMissed',
iconColor: 'var(--danger-color)', iconColor: 'var(--danger-color)',
}, },
'started-call': { 'started-call': {
notificationTextKey: 'startedACall', notificationTextKey: 'callsYouCalled',
iconType: 'callOutgoing', iconType: 'callOutgoing',
iconColor: 'inherit', iconColor: 'inherit',
}, },
@ -36,7 +36,7 @@ const style: StyleType = {
iconType: 'callIncoming', iconType: 'callIncoming',
iconColor: 'inherit', iconColor: 'inherit',
}, },
}; } satisfies StyleType;
export const CallNotification = (props: PropsForCallNotification) => { export const CallNotification = (props: PropsForCallNotification) => {
const { messageId, notificationType } = props; const { messageId, notificationType } = props;
@ -49,12 +49,11 @@ export const CallNotification = (props: PropsForCallNotification) => {
nickname || displayNameInProfile || (selectedConvoId && PubKey.shorten(selectedConvoId)); nickname || displayNameInProfile || (selectedConvoId && PubKey.shorten(selectedConvoId));
const styleItem = style[notificationType]; const styleItem = style[notificationType];
const notificationText = window.i18n(styleItem.notificationTextKey, [
displayName || window.i18n('unknown'), const notificationText = window.i18n(styleItem.notificationTextKey, {
]); name: displayName ?? window.i18n('unknown'),
if (!window.i18n(styleItem.notificationTextKey)) { });
throw new Error(`invalid i18n key ${styleItem.notificationTextKey}`);
}
const iconType = styleItem.iconType; const iconType = styleItem.iconType;
const iconColor = styleItem.iconColor; const iconColor = styleItem.iconColor;

Loading…
Cancel
Save