Fix view source shows original event for an edited message (#377)

Signed-off-by: Clament John <cj@hackerlab.in>

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.
This commit is contained in:
Clament John 2022-03-15 17:20:43 +05:30 committed by GitHub
parent 6e9cd02b2b
commit 92a3a8d6fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(({
</MenuItem>
<MenuItem
iconSrc={CmdIC}
onClick={() => openViewSource(mEvent)}
onClick={() => handleOpenViewSource(mEvent, roomTimeline)}
>
View source
</MenuItem>