|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
|
|
|
import { PropsForExpirationTimer } from '../../state/ducks/conversations';
|
|
|
|
import { NotificationBubble } from './message/message-item/notification-bubble/NotificationBubble';
|
|
|
|
import { ExpirableReadableMessage } from './message/message-item/ExpirableReadableMessage';
|
|
|
|
|
|
|
|
export const TimerNotification = (props: PropsForExpirationTimer) => {
|
|
|
|
const {
|
|
|
|
messageId,
|
|
|
|
receivedAt,
|
|
|
|
isUnread,
|
|
|
|
pubkey,
|
|
|
|
profileName,
|
|
|
|
expirationType,
|
|
|
|
timespan,
|
|
|
|
type,
|
|
|
|
disabled,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const contact = profileName || pubkey;
|
|
|
|
const mode =
|
|
|
|
expirationType === 'deleteAfterRead'
|
|
|
|
? window.i18n('timerModeRead')
|
|
|
|
: window.i18n('timerModeSent');
|
|
|
|
|
|
|
|
let textToRender: string | undefined;
|
|
|
|
switch (type) {
|
|
|
|
case 'fromOther':
|
|
|
|
textToRender = disabled
|
|
|
|
? window.i18n('disabledDisappearingMessages', [contact, timespan])
|
|
|
|
: window.i18n('theyChangedTheTimer', [contact, timespan, mode]);
|
|
|
|
break;
|
|
|
|
case 'fromMe':
|
|
|
|
textToRender = disabled
|
|
|
|
? window.i18n('youDisabledDisappearingMessages')
|
|
|
|
: window.i18n('youChangedTheTimer', [timespan, mode]);
|
|
|
|
break;
|
|
|
|
// TODO update synced control message?
|
|
|
|
case 'fromSync':
|
|
|
|
textToRender = disabled
|
|
|
|
? window.i18n('disappearingMessagesDisabled')
|
|
|
|
: window.i18n('timerSetOnSync', [timespan]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!textToRender || textToRender.length === 0) {
|
|
|
|
throw new Error('textToRender invalid key used TimerNotification');
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<ExpirableReadableMessage
|
|
|
|
convoId={props.convoId}
|
|
|
|
messageId={messageId}
|
|
|
|
direction={props.direction}
|
|
|
|
receivedAt={receivedAt}
|
|
|
|
isUnread={isUnread}
|
|
|
|
expirationLength={props.expirationLength}
|
|
|
|
expirationTimestamp={props.expirationTimestamp}
|
|
|
|
isExpired={props.isExpired}
|
|
|
|
key={`readable-message-${messageId}`}
|
|
|
|
>
|
|
|
|
<NotificationBubble
|
|
|
|
iconType="stopwatch"
|
|
|
|
iconColor="inherit"
|
|
|
|
notificationText={textToRender}
|
|
|
|
/>
|
|
|
|
</ExpirableReadableMessage>
|
|
|
|
);
|
|
|
|
};
|