session-desktop/ts/components/conversation/TimerNotification.tsx

82 lines
2.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { ContactName } from './ContactName';
import { Intl } from '../Intl';
2019-01-14 22:49:58 +01:00
import { LocalizerType } from '../../types/Util';
import { missingCaseError } from '../../util/missingCaseError';
2020-02-25 07:26:45 +01:00
import { SessionIcon, SessionIconSize, SessionIconType } from '../session/icon';
interface Props {
type: 'fromOther' | 'fromMe' | 'fromSync';
phoneNumber: string;
profileName?: string;
name?: string;
disabled: boolean;
timespan: string;
}
export class TimerNotification extends React.Component<Props> {
public renderContents() {
const { phoneNumber, profileName, timespan, type, disabled } = this.props;
2019-01-14 22:49:58 +01:00
const changeKey = disabled
? 'disabledDisappearingMessages'
: 'theyChangedTheTimer';
2020-07-03 08:38:50 +02:00
const displayedPubkey = profileName
? window.shortenPubkey(phoneNumber)
: phoneNumber;
2020-04-06 08:32:50 +02:00
switch (type) {
case 'fromOther':
return (
<Intl
i18n={window.i18n}
2019-01-14 22:49:58 +01:00
id={changeKey}
components={[
<ContactName
i18n={window.i18n}
key="external-1"
2020-07-03 08:38:50 +02:00
phoneNumber={displayedPubkey}
profileName={profileName}
name={name}
2020-07-03 08:38:50 +02:00
module="module-message__author"
boldProfileName={true}
shouldShowPubkey={false}
/>,
timespan,
]}
/>
);
case 'fromMe':
return disabled
? window.i18n('youDisabledDisappearingMessages')
: window.i18n('youChangedTheTimer', [timespan]);
case 'fromSync':
return disabled
? window.i18n('disappearingMessagesDisabled')
: window.i18n('timerSetOnSync', [timespan]);
default:
throw missingCaseError(type);
}
}
public render() {
return (
<div className="module-timer-notification">
2020-04-06 07:34:35 +02:00
<div className="module-timer-notification__message">
<div>
2020-02-25 07:26:45 +01:00
<SessionIcon
iconType={SessionIconType.Stopwatch}
2020-04-06 07:34:35 +02:00
iconSize={SessionIconSize.Small}
iconColor={'#ABABAB'}
2020-02-25 07:26:45 +01:00
/>
</div>
2020-04-06 07:34:35 +02:00
2020-07-08 09:12:34 +02:00
<div>{this.renderContents()}</div>
</div>
</div>
);
}
}