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