indent and use double quotes
parent
43a111d4c9
commit
7cd3f51c56
|
@ -3,7 +3,7 @@ import JSZip from "jszip";
|
|||
import { decryptFile } from "../DecryptFile";
|
||||
import { mediaFromContent, mediaFromMxc } from "../../customisations/Media";
|
||||
import { textForEvent } from "../../TextForEvent";
|
||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { getUserNameColorClass } from "../FormattingUtils";
|
||||
import { Exporter } from "./Exporter";
|
||||
|
@ -274,16 +274,16 @@ div.mx_selected {
|
|||
`;
|
||||
|
||||
export default class HTMLExporter extends Exporter {
|
||||
protected zip: JSZip;
|
||||
protected avatars: Map<string, boolean>;
|
||||
protected zip: JSZip;
|
||||
protected avatars: Map<string, boolean>;
|
||||
|
||||
constructor(res: MatrixEvent[], room: Room) {
|
||||
constructor(res: MatrixEvent[], room: Room) {
|
||||
super(res, room);
|
||||
this.zip = new JSZip();
|
||||
this.avatars = new Map<string, boolean>();
|
||||
}
|
||||
}
|
||||
|
||||
protected wrapHTML(content: string, room: Room) {
|
||||
protected wrapHTML(content: string, room: Room) {
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -308,16 +308,15 @@ protected wrapHTML(content: string, room: Room) {
|
|||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
|
||||
protected isEdit(event: MatrixEvent) {
|
||||
protected isEdit(event: MatrixEvent) {
|
||||
if (event.getType() === "m.room.message" && event.getContent().hasOwnProperty("m.new_content")) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected async getUserAvatar(event: MatrixEvent) {
|
||||
protected async getUserAvatar(event: MatrixEvent) {
|
||||
const member = event.sender;
|
||||
if (!member.getMxcAvatarUrl()) {
|
||||
return `
|
||||
|
@ -354,10 +353,9 @@ protected async getUserAvatar(event: MatrixEvent) {
|
|||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected async getImageData(event: MatrixEvent) {
|
||||
protected async getImageData(event: MatrixEvent) {
|
||||
let blob: Blob;
|
||||
try {
|
||||
const isEncrypted = event.isEncrypted();
|
||||
|
@ -373,19 +371,19 @@ protected async getImageData(event: MatrixEvent) {
|
|||
console.log("Error decrypting image");
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets the event_id of an event to which an event is replied
|
||||
protected getBaseEventId = (event: MatrixEvent) => {
|
||||
//Gets the event_id of an event to which an event is replied
|
||||
protected getBaseEventId = (event: MatrixEvent) => {
|
||||
const isEncrypted = event.isEncrypted();
|
||||
|
||||
// If encrypted, in_reply_to lies in event.event.content
|
||||
const content = isEncrypted ? event.event.content : event.getContent();
|
||||
const relatesTo = content["m.relates_to"];
|
||||
return (relatesTo && relatesTo["m.in_reply_to"]) ? relatesTo["m.in_reply_to"]["event_id"] : null;
|
||||
};
|
||||
};
|
||||
|
||||
protected dateSeparator(event: MatrixEvent, prevEvent: MatrixEvent) {
|
||||
protected dateSeparator(event: MatrixEvent, prevEvent: MatrixEvent) {
|
||||
const prevDate = prevEvent ? new Date(prevEvent.getTs()) : null;
|
||||
const currDate = new Date(event.getTs());
|
||||
if (!prevDate || currDate.setHours(0, 0, 0, 0) !== prevDate.setHours(0, 0, 0, 0)) {
|
||||
|
@ -399,9 +397,9 @@ protected dateSeparator(event: MatrixEvent, prevEvent: MatrixEvent) {
|
|||
`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected async createMessageBody(event: MatrixEvent, joined = false, isReply = false, replyId = null) {
|
||||
protected async createMessageBody(event: MatrixEvent, joined = false, isReply = false, replyId = null) {
|
||||
const userPic = await this.getUserAvatar(event);
|
||||
let messageBody = "";
|
||||
switch (event.getContent().msgtype) {
|
||||
|
@ -444,9 +442,9 @@ protected async createMessageBody(event: MatrixEvent, joined = false, isReply =
|
|||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
protected async createHTML(events: MatrixEvent[], room: Room) {
|
||||
protected async createHTML(events: MatrixEvent[], room: Room) {
|
||||
let content = "";
|
||||
let prevEvent = null;
|
||||
for (const event of events) {
|
||||
|
@ -474,10 +472,9 @@ protected async createHTML(events: MatrixEvent[], room: Room) {
|
|||
prevEvent = event;
|
||||
}
|
||||
return this.wrapHTML(content, room);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async export() {
|
||||
public async export() {
|
||||
const html = await this.createHTML(this.res, this.room);
|
||||
|
||||
this.zip.file("index.html", html);
|
||||
|
@ -513,6 +510,6 @@ public async export() {
|
|||
writer.close();
|
||||
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue