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

94 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2018 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2022-11-18 00:45:19 +00:00
import type { ReactNode } from 'react';
import React from 'react';
import { ContactName } from './ContactName';
import { SystemMessage } from './SystemMessage';
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
import * as expirationTimer from '../../util/expirationTimer';
2022-11-16 20:18:02 +00:00
import type { DurationInSeconds } from '../../util/durations';
import * as log from '../../logging/log';
export type TimerNotificationType =
| 'fromOther'
| 'fromMe'
| 'fromSync'
| 'fromMember';
// We can't always use destructuring assignment because of the complexity of this props
// type.
2022-11-18 00:45:19 +00:00
export type PropsData = {
type: TimerNotificationType;
2020-07-24 01:35:32 +00:00
title: string;
} & (
| { disabled: true }
| {
disabled: false;
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds;
}
);
type PropsHousekeeping = {
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
};
2020-08-26 00:41:43 +00:00
export type Props = PropsData & PropsHousekeeping;
2022-11-18 00:45:19 +00:00
export function TimerNotification(props: Props): JSX.Element {
const { disabled, i18n, title, type } = props;
let timespan: string;
2023-05-04 18:04:22 +00:00
if (disabled) {
timespan = ''; // Set to the empty string to satisfy types
} else {
timespan = expirationTimer.format(i18n, props.expireTimer);
}
const name = <ContactName key="external-1" title={title} />;
let message: ReactNode;
switch (type) {
case 'fromOther':
2023-05-04 18:04:22 +00:00
message = disabled ? (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:disabledDisappearingMessages"
components={{ name }}
/>
) : (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:theyChangedTheTimer"
components={{ name, time: timespan }}
/>
);
break;
case 'fromMe':
message = disabled
2023-03-30 00:03:25 +00:00
? i18n('icu:youDisabledDisappearingMessages')
: i18n('icu:youChangedTheTimer', { time: timespan });
break;
case 'fromSync':
message = disabled
2023-03-30 00:03:25 +00:00
? i18n('icu:disappearingMessagesDisabled')
: i18n('icu:timerSetOnSync', { time: timespan });
break;
case 'fromMember':
message = disabled
2023-03-30 00:03:25 +00:00
? i18n('icu:disappearingMessagesDisabledByMember')
: i18n('icu:timerSetByMember', { time: timespan });
break;
default:
log.warn('TimerNotification: unsupported type provided:', type);
break;
}
const icon = disabled ? 'timer-disabled' : 'timer';
return <SystemMessage icon={icon} contents={message} />;
2022-11-18 00:45:19 +00:00
}