Fix html exports by adding SDKContext (#30987)
* Fix html exports by adding SDKContext Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b4396f5943
commit
56f6c1ef46
@@ -30,6 +30,7 @@ import MatrixClientContext from "../../contexts/MatrixClientContext";
|
|||||||
import getExportCSS from "./exportCSS";
|
import getExportCSS from "./exportCSS";
|
||||||
import { textForEvent } from "../../TextForEvent";
|
import { textForEvent } from "../../TextForEvent";
|
||||||
import { haveRendererForEvent } from "../../events/EventTileFactory";
|
import { haveRendererForEvent } from "../../events/EventTileFactory";
|
||||||
|
import { SDKContext, SdkContextClass } from "../../contexts/SDKContext.ts";
|
||||||
|
|
||||||
import exportJS from "!!raw-loader!./exportJS";
|
import exportJS from "!!raw-loader!./exportJS";
|
||||||
|
|
||||||
@@ -267,29 +268,31 @@ export default class HTMLExporter extends Exporter {
|
|||||||
return (
|
return (
|
||||||
<div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
<div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
||||||
<MatrixClientContext.Provider value={this.room.client}>
|
<MatrixClientContext.Provider value={this.room.client}>
|
||||||
<TooltipProvider>
|
<SDKContext.Provider value={SdkContextClass.instance}>
|
||||||
<EventTile
|
<TooltipProvider>
|
||||||
mxEvent={mxEv}
|
<EventTile
|
||||||
continuation={continuation}
|
mxEvent={mxEv}
|
||||||
isRedacted={mxEv.isRedacted()}
|
continuation={continuation}
|
||||||
replacingEventId={mxEv.replacingEventId()}
|
isRedacted={mxEv.isRedacted()}
|
||||||
forExport={true}
|
replacingEventId={mxEv.replacingEventId()}
|
||||||
alwaysShowTimestamps={true}
|
forExport={true}
|
||||||
showUrlPreview={false}
|
alwaysShowTimestamps={true}
|
||||||
checkUnmounting={() => false}
|
showUrlPreview={false}
|
||||||
isTwelveHour={false}
|
checkUnmounting={() => false}
|
||||||
last={false}
|
isTwelveHour={false}
|
||||||
lastInSection={false}
|
last={false}
|
||||||
permalinkCreator={this.permalinkCreator}
|
lastInSection={false}
|
||||||
lastSuccessful={false}
|
permalinkCreator={this.permalinkCreator}
|
||||||
isSelectedEvent={false}
|
lastSuccessful={false}
|
||||||
showReactions={true}
|
isSelectedEvent={false}
|
||||||
layout={Layout.Group}
|
showReactions={true}
|
||||||
showReadReceipts={false}
|
layout={Layout.Group}
|
||||||
getRelationsForEvent={this.getRelationsForEvent}
|
showReadReceipts={false}
|
||||||
ref={ref}
|
getRelationsForEvent={this.getRelationsForEvent}
|
||||||
/>
|
ref={ref}
|
||||||
</TooltipProvider>
|
/>
|
||||||
|
</TooltipProvider>
|
||||||
|
</SDKContext.Provider>
|
||||||
</MatrixClientContext.Provider>
|
</MatrixClientContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import HTMLExporter from "../../../../src/utils/exportUtils/HtmlExport";
|
|||||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||||
import { mediaFromMxc } from "../../../../src/customisations/Media";
|
import { mediaFromMxc } from "../../../../src/customisations/Media";
|
||||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||||
|
import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
|
||||||
|
|
||||||
jest.mock("jszip");
|
jest.mock("jszip");
|
||||||
jest.mock("../../../../src/settings/SettingsStore");
|
jest.mock("../../../../src/settings/SettingsStore");
|
||||||
@@ -75,6 +76,20 @@ const EVENT_ATTACHMENT_MALFORMED: IRoomEvent = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const EVENT_MENTION: IRoomEvent = {
|
||||||
|
event_id: "$4",
|
||||||
|
type: EventType.RoomMessage,
|
||||||
|
sender: "@bob:example.com",
|
||||||
|
origin_server_ts: 0,
|
||||||
|
content: {
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "Message Alex",
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": 'Message <a href="https://matrix.to/#/@alex:example.org">@alex:example.org</a>',
|
||||||
|
"m.mentions": { user_ids: ["@alex:example.org"] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
describe("HTMLExport", () => {
|
describe("HTMLExport", () => {
|
||||||
let client: jest.Mocked<MatrixClient>;
|
let client: jest.Mocked<MatrixClient>;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
@@ -96,6 +111,7 @@ describe("HTMLExport", () => {
|
|||||||
jest.setSystemTime(REPEATABLE_DATE);
|
jest.setSystemTime(REPEATABLE_DATE);
|
||||||
|
|
||||||
client = stubClient() as jest.Mocked<MatrixClient>;
|
client = stubClient() as jest.Mocked<MatrixClient>;
|
||||||
|
SdkContextClass.instance.client = client;
|
||||||
DMRoomMap.makeShared(client);
|
DMRoomMap.makeShared(client);
|
||||||
|
|
||||||
room = new Room("!myroom:example.org", client, "@me:example.org");
|
room = new Room("!myroom:example.org", client, "@me:example.org");
|
||||||
@@ -716,4 +732,23 @@ describe("HTMLExport", () => {
|
|||||||
const file = getMessageFile(exporter);
|
const file = getMessageFile(exporter);
|
||||||
expect(file).not.toBeUndefined();
|
expect(file).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not crash when exporting mentions", async () => {
|
||||||
|
mockMessages(EVENT_MESSAGE, EVENT_MENTION);
|
||||||
|
const exporter = new HTMLExporter(
|
||||||
|
room,
|
||||||
|
ExportType.LastNMessages,
|
||||||
|
{
|
||||||
|
attachmentsIncluded: false,
|
||||||
|
maxSize: 1_024 * 1_024,
|
||||||
|
numberOfMessages: 40,
|
||||||
|
},
|
||||||
|
() => {},
|
||||||
|
);
|
||||||
|
|
||||||
|
await exporter.export();
|
||||||
|
|
||||||
|
const file = getMessageFile(exporter);
|
||||||
|
expect(file).not.toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user