Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Display redaction reason #5604

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/components/views/messages/RedactedBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,44 @@ interface IProps {

const RedactedBody = React.forwardRef<any, IProps>(({mxEvent}, ref) => {
const cli: MatrixClient = useContext(MatrixClientContext);

let text = _t("Message deleted");
const room = cli.getRoom(mxEvent.getRoomId());
const unsigned = mxEvent.getUnsigned();
const redactedBecauseUserId = unsigned && unsigned.redacted_because && unsigned.redacted_because.sender;
if (redactedBecauseUserId && redactedBecauseUserId !== mxEvent.getSender()) {
const room = cli.getRoom(mxEvent.getRoomId());
const sender = room && room.getMember(redactedBecauseUserId);
text = _t("Message deleted by %(name)s", { name: sender ? sender.name : redactedBecauseUserId });
}
const redactionEvent = mxEvent.getRedactionEvent();
const redactionReason = redactionEvent.content.reason;
const redactedBy = unsigned.redacted_because.sender;
const sender = room && room.getMember(redactedBy);
const timestamp = unsigned.redacted_because.origin_server_ts;

// Set title
const showTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps");
const fullDate = formatFullDate(new Date(unsigned.redacted_because.origin_server_ts), showTwelveHour);
const fullDate = formatFullDate(new Date(timestamp), showTwelveHour);
const titleText = _t("Message deleted on %(date)s", { date: fullDate });

// Set text
let text;
if (redactionReason && redactedBy && redactedBy !== mxEvent.getSender()) {
// We have both redactBy and redactionReason
text = _t(
"Message deleted by %(redactedBy)s. Reason: %(reason)s",
{reason: redactionReason, redactedBy: sender ? sender.name : redactedBy},
);
} else if (redactionReason) {
// We have redaction reason
text = _t(
"Message deleted. Reason: %(reason)s",
{reason: redactionReason},
);
} else if (redactedBy && redactedBy !== mxEvent.getSender()) {
// We have redactedBy
text = _t(
"Message deleted by %(redactedBy)s",
{ redactedBy: sender ? sender.name : redactedBy },
);
} else {
// We don't have anything
text = _t("Message deleted.");
}

return (
<span className="mx_RedactedBody" ref={ref} title={titleText}>
{ text }
Expand Down
6 changes: 4 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,11 @@
"Reactions": "Reactions",
"<reactors/><reactedWith> reacted with %(content)s</reactedWith>": "<reactors/><reactedWith> reacted with %(content)s</reactedWith>",
"<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>": "<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>",
"Message deleted": "Message deleted",
"Message deleted by %(name)s": "Message deleted by %(name)s",
"Message deleted on %(date)s": "Message deleted on %(date)s",
"Message deleted by %(redactedBy)s. Reason: %(reason)s": "Message deleted by %(redactedBy)s. Reason: %(reason)s",
"Message deleted. Reason: %(reason)s": "Message deleted. Reason: %(reason)s",
"Message deleted by %(redactedBy)s": "Message deleted by %(redactedBy)s",
"Message deleted.": "Message deleted.",
"%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s",
"%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.",
"%(senderDisplayName)s changed the room avatar to <img/>": "%(senderDisplayName)s changed the room avatar to <img/>",
Expand Down