isExporting -> forExport and wrap EventTile with Context Provider

This commit is contained in:
Jaiwanth 2021-06-08 18:35:45 +05:30
parent 9e298e9f45
commit 6f8c1638aa
8 changed files with 55 additions and 53 deletions

View file

@ -23,16 +23,20 @@ import exportCSS from "./exportCSS";
import exportJS from "./exportJS";
import exportIcons from "./exportIcons";
import { exportTypes } from "./exportUtils";
import MatrixClientContext from "../../contexts/MatrixClientContext";
import { MatrixClient } from "matrix-js-sdk";
export default class HTMLExporter extends Exporter {
protected zip: JSZip;
protected avatars: Map<string, boolean>;
protected permalinkCreator: RoomPermalinkCreator;
protected matrixClient: MatrixClient;
constructor(room: Room, exportType: exportTypes, numberOfEvents?: number) {
super(room, exportType, numberOfEvents);
this.zip = new JSZip();
this.avatars = new Map<string, boolean>();
this.matrixClient = MatrixClientPeg.get();
this.permalinkCreator = new RoomPermalinkCreator(this.room);
window.addEventListener("beforeunload", this.onBeforeUnload)
}
@ -214,7 +218,7 @@ export default class HTMLExporter extends Exporter {
protected getDateSeparator(event: MatrixEvent) {
const ts = event.getTs();
const dateSeparator = <li key={ts}><DateSeparator isExporting={true} key={ts} ts={ts} /></li>;
const dateSeparator = <li key={ts}><DateSeparator forExport={true} key={ts} ts={ts} /></li>;
return renderToStaticMarkup(dateSeparator);
}
@ -258,30 +262,32 @@ export default class HTMLExporter extends Exporter {
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
return <li className="mx_Export_EventWrapper" id={mxEv.getId()}>
<EventTile
mxEvent={mxEv}
continuation={continuation}
isRedacted={mxEv.isRedacted()}
replacingEventId={mxEv.replacingEventId()}
isExporting={true}
readReceipts={null}
readReceiptMap={null}
showUrlPreview={false}
checkUnmounting={() => false}
isTwelveHour={false}
last={false}
mediaSrc={mediaSrc}
avatarSrc={hasAvatar ? `users/${mxEv.sender.userId}` : null}
lastInSection={false}
permalinkCreator={this.permalinkCreator}
lastSuccessful={false}
isSelectedEvent={false}
getRelationsForEvent={null}
showReactions={false}
layout={Layout.Group}
enableFlair={false}
showReadReceipts={false}
/>
<MatrixClientContext.Provider value = {this.matrixClient}>
<EventTile
mxEvent={mxEv}
continuation={continuation}
isRedacted={mxEv.isRedacted()}
replacingEventId={mxEv.replacingEventId()}
forExport={true}
readReceipts={null}
readReceiptMap={null}
showUrlPreview={false}
checkUnmounting={() => false}
isTwelveHour={false}
last={false}
mediaSrc={mediaSrc}
avatarSrc={hasAvatar ? `users/${mxEv.sender.userId}` : null}
lastInSection={false}
permalinkCreator={this.permalinkCreator}
lastSuccessful={false}
isSelectedEvent={false}
getRelationsForEvent={null}
showReactions={false}
layout={Layout.Group}
enableFlair={false}
showReadReceipts={false}
/>
</MatrixClientContext.Provider>
</li>
}

View file

@ -10,6 +10,7 @@ export enum exportFormats {
export enum exportTypes {
TIMELINE = "TIMELINE",
BEGINNING = "BEGINNING",
START_DATE = "START_DATE",
LAST_N_MESSAGES = "LAST_N_MESSAGES",
}
@ -17,11 +18,11 @@ const exportConversationalHistory = async (
room: Room,
format: string,
exportType: exportTypes,
numberOfEvents?: number,
exportTypeMetadata?: number,
) => {
switch (format) {
case exportFormats.HTML:
await new HTMLExporter(room, exportType, numberOfEvents).export();
await new HTMLExporter(room, exportType, exportTypeMetadata).export();
break;
case exportFormats.JSON:
break;