Files
ThreadNet-Web/src/components/views/messages/RedactedBody.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-04-24 15:07:39 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
2020-04-24 15:07:39 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2020-04-24 15:07:39 +01:00
*/
2023-07-07 13:37:26 +01:00
import React, { ForwardRefExoticComponent, useContext } from "react";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
2021-10-22 17:23:32 -05:00
2020-04-24 15:07:39 +01:00
import { _t } from "../../../languageHandler";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { formatFullDate } from "../../../DateUtils";
2020-05-22 14:41:25 -05:00
import SettingsStore from "../../../settings/SettingsStore";
2021-07-16 10:57:14 -06:00
import { IBodyProps } from "./IBodyProps";
2021-09-24 19:55:52 +02:00
2023-07-07 13:37:26 +01:00
const RedactedBody = React.forwardRef<any, IBodyProps>(({ mxEvent }, ref) => {
const cli: MatrixClient = useContext(MatrixClientContext);
let text = _t("timeline|self_redaction");
2020-04-27 23:53:32 +01:00
const unsigned = mxEvent.getUnsigned();
const redactedBecauseUserId = unsigned && unsigned.redacted_because && unsigned.redacted_because.sender;
if (redactedBecauseUserId && redactedBecauseUserId !== mxEvent.getSender()) {
2020-04-24 15:07:39 +01:00
const room = cli.getRoom(mxEvent.getRoomId());
const sender = room && room.getMember(redactedBecauseUserId);
text = _t("timeline|redaction", { name: sender ? sender.name : redactedBecauseUserId });
2020-04-24 15:07:39 +01:00
}
2020-05-22 14:41:25 -05:00
const showTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps");
const fullDate = unsigned.redacted_because
? formatFullDate(new Date(unsigned.redacted_because.origin_server_ts), showTwelveHour)
: undefined;
const titleText = fullDate ? _t("timeline|redacted|tooltip", { date: fullDate }) : undefined;
2020-05-22 14:41:25 -05:00
2020-04-24 15:07:39 +01:00
return (
2020-05-22 14:41:25 -05:00
<span className="mx_RedactedBody" ref={ref} title={titleText}>
2020-04-24 15:07:39 +01:00
{text}
</span>
);
2023-07-07 13:37:26 +01:00
}) as ForwardRefExoticComponent<IBodyProps>;
2020-04-24 15:07:39 +01:00
export default RedactedBody;