From a47117e3b025f1a44f4538be31a7ededd5aca395 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Sat, 22 May 2021 11:55:57 +0530 Subject: [PATCH] Do not process edit events as they are already considered --- src/utils/exportUtils/HtmlExport.ts | 33 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/utils/exportUtils/HtmlExport.ts b/src/utils/exportUtils/HtmlExport.ts index 6ca7f8057b..97e97fdc1e 100644 --- a/src/utils/exportUtils/HtmlExport.ts +++ b/src/utils/exportUtils/HtmlExport.ts @@ -324,6 +324,10 @@ const getBaseEventId = (event: MatrixEvent) => { return (relatesTo && relatesTo["m.in_reply_to"]) ? relatesTo["m.in_reply_to"]["event_id"] : null; }; +const isEdit = (event: MatrixEvent) => { + if (event.getType() === "m.room.message" && event.getContent().hasOwnProperty("m.new_content")) return true; + return false; +} const dateSeparator = (event: MatrixEvent, prevEvent: MatrixEvent) => { const prevDate = prevEvent ? new Date(prevEvent.getTs()) : null; @@ -383,20 +387,21 @@ const createMessageBody = async (event: MatrixEvent, joined = false, isReply = f return `
${!joined ? userPic : ``} -
-
- ${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)} -
- ${!joined ? `
- ${event.sender.name} -
`: ``} +
+
+ ${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)} +
+ ${!joined ? ` +
+ ${event.sender.name} +
`: ``} ${isReply ? - `
- In reply to this message -
`: ``} + `
+ In reply to this message +
`: ``} ${messageBody} -
-
+
+ `; }; @@ -405,6 +410,8 @@ const createHTML = async (events: MatrixEvent[], room: Room) => { let content = ""; let prevEvent = null; for (const event of events) { + // As the getContent of the edited event fetches the latest edit, there is no need to process edit events + if (isEdit(event)) continue; content += dateSeparator(event, prevEvent); if (event.getType() === "m.room.message") { @@ -430,7 +437,7 @@ const createHTML = async (events: MatrixEvent[], room: Room) => { }; const avatars = new Map(); -let zip; +let zip: any; const exportAsHTML = async (res: MatrixEvent[], room: Room) => { zip = new JSZip();