2021-05-03 23:24:40 +00:00
|
|
|
// Copyright 2018-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { FunctionComponent, ReactNode } from 'react';
|
|
|
|
import React from 'react';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
import { ContactName } from './ContactName';
|
2021-09-07 19:55:03 +00:00
|
|
|
import { SystemMessage } from './SystemMessage';
|
2018-07-09 21:29:13 +00:00
|
|
|
import { Intl } from '../Intl';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2021-05-03 23:24:40 +00:00
|
|
|
import * as expirationTimer from '../../util/expirationTimer';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-09-24 20:57:54 +00:00
|
|
|
export type TimerNotificationType =
|
|
|
|
| 'fromOther'
|
|
|
|
| 'fromMe'
|
|
|
|
| 'fromSync'
|
|
|
|
| 'fromMember';
|
|
|
|
|
2021-05-03 23:24:40 +00:00
|
|
|
// We can't always use destructuring assignment because of the complexity of this props
|
|
|
|
// type.
|
|
|
|
/* eslint-disable react/destructuring-assignment */
|
2019-03-20 17:42:28 +00:00
|
|
|
export type PropsData = {
|
2020-09-24 20:57:54 +00:00
|
|
|
type: TimerNotificationType;
|
2020-07-24 01:35:32 +00:00
|
|
|
title: string;
|
2021-05-03 23:24:40 +00:00
|
|
|
} & (
|
|
|
|
| { disabled: true }
|
|
|
|
| {
|
|
|
|
disabled: false;
|
|
|
|
expireTimer: number;
|
|
|
|
}
|
|
|
|
);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
type PropsHousekeeping = {
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 00:41:43 +00:00
|
|
|
export type Props = PropsData & PropsHousekeeping;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-05-03 23:24:40 +00:00
|
|
|
export const TimerNotification: FunctionComponent<Props> = props => {
|
2021-09-16 16:15:43 +00:00
|
|
|
const { disabled, i18n, title, type } = props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-05-03 23:24:40 +00:00
|
|
|
let changeKey: string;
|
|
|
|
let timespan: string;
|
|
|
|
if (props.disabled) {
|
|
|
|
changeKey = 'disabledDisappearingMessages';
|
|
|
|
timespan = ''; // Set to the empty string to satisfy types
|
|
|
|
} else {
|
|
|
|
changeKey = 'theyChangedTheTimer';
|
|
|
|
timespan = expirationTimer.format(i18n, props.expireTimer);
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 23:24:40 +00:00
|
|
|
let message: ReactNode;
|
|
|
|
switch (type) {
|
|
|
|
case 'fromOther':
|
|
|
|
message = (
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
|
|
|
id={changeKey}
|
|
|
|
components={{
|
2021-09-16 16:15:43 +00:00
|
|
|
name: <ContactName key="external-1" title={title} />,
|
2021-05-03 23:24:40 +00:00
|
|
|
time: timespan,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'fromMe':
|
|
|
|
message = disabled
|
|
|
|
? i18n('youDisabledDisappearingMessages')
|
|
|
|
: i18n('youChangedTheTimer', [timespan]);
|
|
|
|
break;
|
|
|
|
case 'fromSync':
|
|
|
|
message = disabled
|
|
|
|
? i18n('disappearingMessagesDisabled')
|
|
|
|
: i18n('timerSetOnSync', [timespan]);
|
|
|
|
break;
|
|
|
|
case 'fromMember':
|
|
|
|
message = disabled
|
|
|
|
? i18n('disappearingMessagesDisabledByMember')
|
|
|
|
: i18n('timerSetByMember', [timespan]);
|
|
|
|
break;
|
|
|
|
default:
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('TimerNotification: unsupported type provided:', type);
|
2021-05-03 23:24:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-09-07 19:55:03 +00:00
|
|
|
const icon = disabled ? 'timer-disabled' : 'timer';
|
|
|
|
|
|
|
|
return <SystemMessage icon={icon} contents={message} />;
|
2021-05-03 23:24:40 +00:00
|
|
|
};
|