mirror of https://github.com/vector-im/riot-web
Do not process edit events as they are already considered
parent
0bf65da70f
commit
a47117e3b0
|
@ -324,6 +324,10 @@ const getBaseEventId = (event: MatrixEvent) => {
|
||||||
return (relatesTo && relatesTo["m.in_reply_to"]) ? relatesTo["m.in_reply_to"]["event_id"] : null;
|
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 dateSeparator = (event: MatrixEvent, prevEvent: MatrixEvent) => {
|
||||||
const prevDate = prevEvent ? new Date(prevEvent.getTs()) : null;
|
const prevDate = prevEvent ? new Date(prevEvent.getTs()) : null;
|
||||||
|
@ -383,20 +387,21 @@ const createMessageBody = async (event: MatrixEvent, joined = false, isReply = f
|
||||||
return `
|
return `
|
||||||
<div class="message default clearfix ${joined ? `joined` : ``}" id="${event.getId()}">
|
<div class="message default clearfix ${joined ? `joined` : ``}" id="${event.getId()}">
|
||||||
${!joined ? userPic : ``}
|
${!joined ? userPic : ``}
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<div class="pull_right date details" title="${new Date(event.getTs())}">
|
<div class="pull_right date details" title="${new Date(event.getTs())}">
|
||||||
${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)}
|
${new Date(event.getTs()).toLocaleTimeString().slice(0, -3)}
|
||||||
</div>
|
</div>
|
||||||
${!joined ? `<div class="from_name" style="color:${getUserColor(event.sender.name)}">
|
${!joined ? `
|
||||||
${event.sender.name}
|
<div class="from_name" style="color:${getUserColor(event.sender.name)}">
|
||||||
</div>`: ``}
|
${event.sender.name}
|
||||||
|
</div>`: ``}
|
||||||
${isReply ?
|
${isReply ?
|
||||||
`<div class="reply_to details">
|
` <div class="reply_to details">
|
||||||
In reply to <a href="#${replyId}">this message</a>
|
In reply to <a href="#${replyId}">this message</a>
|
||||||
</div>`: ``}
|
</div>`: ``}
|
||||||
${messageBody}
|
${messageBody}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -405,6 +410,8 @@ const createHTML = async (events: MatrixEvent[], room: Room) => {
|
||||||
let content = "";
|
let content = "";
|
||||||
let prevEvent = null;
|
let prevEvent = null;
|
||||||
for (const event of events) {
|
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);
|
content += dateSeparator(event, prevEvent);
|
||||||
|
|
||||||
if (event.getType() === "m.room.message") {
|
if (event.getType() === "m.room.message") {
|
||||||
|
@ -430,7 +437,7 @@ const createHTML = async (events: MatrixEvent[], room: Room) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatars = new Map();
|
const avatars = new Map();
|
||||||
let zip;
|
let zip: any;
|
||||||
|
|
||||||
const exportAsHTML = async (res: MatrixEvent[], room: Room) => {
|
const exportAsHTML = async (res: MatrixEvent[], room: Room) => {
|
||||||
zip = new JSZip();
|
zip = new JSZip();
|
||||||
|
|
Loading…
Reference in New Issue