From 36a69313cdd3e1f9317f47b3a0cb0f6ef96c5dd4 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Tue, 22 Jun 2021 14:53:48 +0530 Subject: [PATCH] Display redactedBecauseUserId for redacted events --- src/TextForEvent.ts | 12 ++++++++++-- src/i18n/strings/en_EN.json | 5 ++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/TextForEvent.ts b/src/TextForEvent.ts index de65733be8..ad3417fd8c 100644 --- a/src/TextForEvent.ts +++ b/src/TextForEvent.ts @@ -244,9 +244,17 @@ function textForServerACLEvent(ev): () => string | null { function textForMessageEvent(ev: MatrixEvent): () => string | null { return () => { const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); - const isRedacted = ev.isRedacted(); let message = ev.getContent().body; - if (isRedacted) message = _t("Message Deleted"); + if (ev.isRedacted()) { + message = _t("Message deleted"); + const unsigned = ev.getUnsigned(); + const redactedBecauseUserId = unsigned && unsigned.redacted_because && unsigned.redacted_because.sender; + if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) { + const room = MatrixClientPeg.get().getRoom(ev.getRoomId()); + const sender = room && room.getMember(redactedBecauseUserId); + message = _t("Message deleted by %(name)s", { name: sender ? sender.name : redactedBecauseUserId }); + } + } if (ev.getContent().msgtype === "m.emote") { message = "* " + senderDisplayName + " " + message; } else if (ev.getContent().msgtype === "m.image") { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 2bad735745..7a25ebfb7a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -526,7 +526,8 @@ "%(senderDisplayName)s set the server ACLs for this room.": "%(senderDisplayName)s set the server ACLs for this room.", "%(senderDisplayName)s changed the server ACLs for this room.": "%(senderDisplayName)s changed the server ACLs for this room.", "🎉 All servers are banned from participating! This room can no longer be used.": "🎉 All servers are banned from participating! This room can no longer be used.", - "Message Deleted": "Message Deleted", + "Message deleted": "Message deleted", + "Message deleted by %(name)s": "Message deleted by %(name)s", "%(senderDisplayName)s sent an image.": "%(senderDisplayName)s sent an image.", "%(senderDisplayName)s sent a sticker.": "%(senderDisplayName)s sent a sticker.", "%(senderName)s set the main address for this room to %(address)s.": "%(senderName)s set the main address for this room to %(address)s.", @@ -1881,8 +1882,6 @@ "Reactions": "Reactions", " reacted with %(content)s": " reacted with %(content)s", "reacted with %(shortName)s": "reacted with %(shortName)s", - "Message deleted": "Message deleted", - "Message deleted by %(name)s": "Message deleted by %(name)s", "Message deleted on %(date)s": "Message deleted on %(date)s", "%(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.",