2018-04-11 23:58:04 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2018-04-11 23:58:04 +01:00
|
|
|
Copyright 2018 Michael Telatynski <7t3chguy@gmail.com>
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2018-04-11 23:58:04 +01:00
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2018-04-11 23:58:04 +01:00
|
|
|
*/
|
|
|
|
|
|
2023-10-17 13:31:41 +01:00
|
|
|
import React, { ReactNode } from "react";
|
2023-10-13 12:26:12 +01:00
|
|
|
import { Tooltip } from "@vector-im/compound-web";
|
2021-12-09 09:10:23 +00:00
|
|
|
|
2021-11-03 10:16:50 +00:00
|
|
|
import { formatFullDate, formatTime, formatFullTime, formatRelativeTime } from "../../../DateUtils";
|
2023-10-14 13:25:36 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2023-10-17 13:31:41 +01:00
|
|
|
import { Icon as LateIcon } from "../../../../res/img/sensor.svg";
|
2021-06-16 10:01:30 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
ts: number;
|
2023-10-14 13:25:36 +01:00
|
|
|
/**
|
|
|
|
|
* If specified will render both the sent-at and received-at timestamps in the tooltip
|
|
|
|
|
*/
|
|
|
|
|
receivedTs?: number;
|
2021-06-16 10:01:30 +01:00
|
|
|
showTwelveHour?: boolean;
|
|
|
|
|
showFullDate?: boolean;
|
|
|
|
|
showSeconds?: boolean;
|
2021-11-03 10:16:50 +00:00
|
|
|
showRelative?: boolean;
|
2021-06-16 10:01:30 +01:00
|
|
|
}
|
2018-04-11 23:58:04 +01:00
|
|
|
|
2021-06-16 10:01:30 +01:00
|
|
|
export default class MessageTimestamp extends React.Component<IProps> {
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2018-04-11 23:58:04 +01:00
|
|
|
const date = new Date(this.props.ts);
|
2023-04-12 15:12:45 +01:00
|
|
|
let timestamp: string;
|
2021-11-03 10:16:50 +00:00
|
|
|
if (this.props.showRelative) {
|
|
|
|
|
timestamp = formatRelativeTime(date, this.props.showTwelveHour);
|
|
|
|
|
} else if (this.props.showFullDate) {
|
2021-04-02 09:25:21 +02:00
|
|
|
timestamp = formatFullDate(date, this.props.showTwelveHour, this.props.showSeconds);
|
|
|
|
|
} else if (this.props.showSeconds) {
|
|
|
|
|
timestamp = formatFullTime(date, this.props.showTwelveHour);
|
|
|
|
|
} else {
|
|
|
|
|
timestamp = formatTime(date, this.props.showTwelveHour);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 13:25:36 +01:00
|
|
|
let label = formatFullDate(date, this.props.showTwelveHour);
|
|
|
|
|
let caption: string | undefined;
|
2023-10-17 13:31:41 +01:00
|
|
|
let icon: ReactNode | undefined;
|
2023-10-14 13:25:36 +01:00
|
|
|
if (this.props.receivedTs !== undefined) {
|
|
|
|
|
label = _t("timeline|message_timestamp_sent_at", { dateTime: label });
|
|
|
|
|
const receivedDate = new Date(this.props.receivedTs);
|
|
|
|
|
caption = _t("timeline|message_timestamp_received_at", {
|
|
|
|
|
dateTime: formatFullDate(receivedDate, this.props.showTwelveHour),
|
|
|
|
|
});
|
2023-10-17 13:31:41 +01:00
|
|
|
icon = <LateIcon className="mx_MessageTimestamp_lateIcon" width="16" height="16" />;
|
2023-10-14 13:25:36 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-11 23:58:04 +01:00
|
|
|
return (
|
2023-10-14 13:25:36 +01:00
|
|
|
<Tooltip label={label} caption={caption}>
|
2023-10-13 12:26:12 +01:00
|
|
|
<span className="mx_MessageTimestamp" aria-hidden={true} aria-live="off">
|
2023-10-17 13:31:41 +01:00
|
|
|
{icon}
|
2023-10-13 12:26:12 +01:00
|
|
|
{timestamp}
|
|
|
|
|
</span>
|
|
|
|
|
</Tooltip>
|
2018-04-11 23:58:04 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|