From 92a3a8d6fa36c2cd0ef1bfbb925432271ec19e72 Mon Sep 17 00:00:00 2001 From: Clament John <17064666+clmnin@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:20:43 +0530 Subject: [PATCH] Fix view source shows original event for an edited message (#377) Signed-off-by: Clament John fixes #376 When we click view source for an edited message we were showing the original event (the unedited event) instead of the latest edited event. --- src/app/molecules/message/Message.jsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/molecules/message/Message.jsx b/src/app/molecules/message/Message.jsx index c011be79..f5e3e2b2 100644 --- a/src/app/molecules/message/Message.jsx +++ b/src/app/molecules/message/Message.jsx @@ -469,6 +469,18 @@ function isMedia(mE) { ); } +// if editedTimeline has mEventId then pass editedMEvent else pass mEvent to openViewSource +function handleOpenViewSource(mEvent, roomTimeline) { + const eventId = mEvent.getId(); + const { editedTimeline } = roomTimeline ?? {}; + let editedMEvent; + if (editedTimeline?.has(eventId)) { + const editedList = editedTimeline.get(eventId); + editedMEvent = editedList[editedList.length - 1]; + } + openViewSource(editedMEvent !== undefined ? editedMEvent : mEvent); +} + const MessageOptions = React.memo(({ roomTimeline, mEvent, edit, reply, }) => { @@ -516,7 +528,7 @@ const MessageOptions = React.memo(({ openViewSource(mEvent)} + onClick={() => handleOpenViewSource(mEvent, roomTimeline)} > View source