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

53 lines
1.4 KiB
TypeScript
Raw Normal View History

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
import type { ReactElement } from 'react';
import React from 'react';
import classNames from 'classnames';
2022-01-26 23:05:26 +00:00
import { formatTime } from '../../util/timestamp';
import type { LocalizerType } from '../../types/Util';
import { Time } from '../Time';
2022-03-08 19:11:11 +00:00
import { useNowThatUpdatesEveryMinute } from '../../hooks/useNowThatUpdatesEveryMinute';
export type Props = {
timestamp: number;
module?: string;
withImageNoCaption?: boolean;
withSticker?: boolean;
2019-06-26 19:33:13 +00:00
withTapToViewExpired?: boolean;
direction?: 'incoming' | 'outgoing';
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
};
export function MessageTimestamp({
direction,
i18n,
module,
timestamp,
withImageNoCaption,
withSticker,
withTapToViewExpired,
}: Readonly<Props>): ReactElement {
2022-03-08 19:11:11 +00:00
const now = useNowThatUpdatesEveryMinute();
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>
);
}