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