2022-01-26 23:05:26 +00:00
|
|
|
// Copyright 2018-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-03-03 20:23:10 +00:00
|
|
|
import type { ReactElement } from 'react';
|
2018-07-09 21:29:13 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2022-01-26 23:05:26 +00:00
|
|
|
import { formatTime } from '../../util/timestamp';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2022-03-03 20:23:10 +00:00
|
|
|
import { Time } from '../Time';
|
2022-03-08 19:11:11 +00:00
|
|
|
import { useNowThatUpdatesEveryMinute } from '../../hooks/useNowThatUpdatesEveryMinute';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type Props = {
|
2022-03-04 04:35:59 +00:00
|
|
|
timestamp: number;
|
2018-07-09 21:29:13 +00:00
|
|
|
module?: string;
|
2018-07-18 03:25:55 +00:00
|
|
|
withImageNoCaption?: boolean;
|
2019-05-16 22:32:11 +00:00
|
|
|
withSticker?: boolean;
|
2019-06-26 19:33:13 +00:00
|
|
|
withTapToViewExpired?: boolean;
|
2018-07-18 03:25:55 +00:00
|
|
|
direction?: 'incoming' | 'outgoing';
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2022-03-03 20:23:10 +00:00
|
|
|
export function MessageTimestamp({
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
module,
|
|
|
|
timestamp,
|
|
|
|
withImageNoCaption,
|
|
|
|
withSticker,
|
|
|
|
withTapToViewExpired,
|
2022-03-04 04:35:59 +00:00
|
|
|
}: Readonly<Props>): ReactElement {
|
2022-03-08 19:11:11 +00:00
|
|
|
const now = useNowThatUpdatesEveryMinute();
|
2022-03-03 20:23:10 +00:00
|
|
|
const moduleName = module || 'module-timestamp';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Time
|
|
|
|
className={classNames(
|
|
|
|
moduleName,
|
|
|
|
direction ? `${moduleName}--${direction}` : null,
|
|
|
|
withTapToViewExpired && direction
|
|
|
|
? `${moduleName}--${direction}-with-tap-to-view-expired`
|
|
|
|
: null,
|
|
|
|
withImageNoCaption ? `${moduleName}--with-image-no-caption` : null,
|
|
|
|
withSticker ? `${moduleName}--with-sticker` : null
|
|
|
|
)}
|
|
|
|
timestamp={timestamp}
|
|
|
|
>
|
|
|
|
{formatTime(i18n, timestamp, now)}
|
|
|
|
</Time>
|
|
|
|
);
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|