Skip to content

Commit 56f6c1e

Browse files
authored
Fix html exports by adding SDKContext (#30987)
* Fix html exports by adding SDKContext Signed-off-by: Michael Telatynski <[email protected]> * delint Signed-off-by: Michael Telatynski <[email protected]> * Add test Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent b4396f5 commit 56f6c1e

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

src/utils/exportUtils/HtmlExport.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import MatrixClientContext from "../../contexts/MatrixClientContext";
3030
import getExportCSS from "./exportCSS";
3131
import { textForEvent } from "../../TextForEvent";
3232
import { haveRendererForEvent } from "../../events/EventTileFactory";
33+
import { SDKContext, SdkContextClass } from "../../contexts/SDKContext.ts";
3334

3435
import exportJS from "!!raw-loader!./exportJS";
3536

@@ -267,29 +268,31 @@ export default class HTMLExporter extends Exporter {
267268
return (
268269
<div className="mx_Export_EventWrapper" id={mxEv.getId()}>
269270
<MatrixClientContext.Provider value={this.room.client}>
270-
<TooltipProvider>
271-
<EventTile
272-
mxEvent={mxEv}
273-
continuation={continuation}
274-
isRedacted={mxEv.isRedacted()}
275-
replacingEventId={mxEv.replacingEventId()}
276-
forExport={true}
277-
alwaysShowTimestamps={true}
278-
showUrlPreview={false}
279-
checkUnmounting={() => false}
280-
isTwelveHour={false}
281-
last={false}
282-
lastInSection={false}
283-
permalinkCreator={this.permalinkCreator}
284-
lastSuccessful={false}
285-
isSelectedEvent={false}
286-
showReactions={true}
287-
layout={Layout.Group}
288-
showReadReceipts={false}
289-
getRelationsForEvent={this.getRelationsForEvent}
290-
ref={ref}
291-
/>
292-
</TooltipProvider>
271+
<SDKContext.Provider value={SdkContextClass.instance}>
272+
<TooltipProvider>
273+
<EventTile
274+
mxEvent={mxEv}
275+
continuation={continuation}
276+
isRedacted={mxEv.isRedacted()}
277+
replacingEventId={mxEv.replacingEventId()}
278+
forExport={true}
279+
alwaysShowTimestamps={true}
280+
showUrlPreview={false}
281+
checkUnmounting={() => false}
282+
isTwelveHour={false}
283+
last={false}
284+
lastInSection={false}
285+
permalinkCreator={this.permalinkCreator}
286+
lastSuccessful={false}
287+
isSelectedEvent={false}
288+
showReactions={true}
289+
layout={Layout.Group}
290+
showReadReceipts={false}
291+
getRelationsForEvent={this.getRelationsForEvent}
292+
ref={ref}
293+
/>
294+
</TooltipProvider>
295+
</SDKContext.Provider>
293296
</MatrixClientContext.Provider>
294297
</div>
295298
);

test/unit-tests/utils/exportUtils/HTMLExport-test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import HTMLExporter from "../../../../src/utils/exportUtils/HtmlExport";
3232
import DMRoomMap from "../../../../src/utils/DMRoomMap";
3333
import { mediaFromMxc } from "../../../../src/customisations/Media";
3434
import SettingsStore from "../../../../src/settings/SettingsStore";
35+
import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
3536

3637
jest.mock("jszip");
3738
jest.mock("../../../../src/settings/SettingsStore");
@@ -75,6 +76,20 @@ const EVENT_ATTACHMENT_MALFORMED: IRoomEvent = {
7576
},
7677
};
7778

79+
const EVENT_MENTION: IRoomEvent = {
80+
event_id: "$4",
81+
type: EventType.RoomMessage,
82+
sender: "@bob:example.com",
83+
origin_server_ts: 0,
84+
content: {
85+
"msgtype": "m.text",
86+
"body": "Message Alex",
87+
"format": "org.matrix.custom.html",
88+
"formatted_body": 'Message <a href="https://matrix.to/#/@alex:example.org">@alex:example.org</a>',
89+
"m.mentions": { user_ids: ["@alex:example.org"] },
90+
},
91+
};
92+
7893
describe("HTMLExport", () => {
7994
let client: jest.Mocked<MatrixClient>;
8095
let room: Room;
@@ -96,6 +111,7 @@ describe("HTMLExport", () => {
96111
jest.setSystemTime(REPEATABLE_DATE);
97112

98113
client = stubClient() as jest.Mocked<MatrixClient>;
114+
SdkContextClass.instance.client = client;
99115
DMRoomMap.makeShared(client);
100116

101117
room = new Room("!myroom:example.org", client, "@me:example.org");
@@ -716,4 +732,23 @@ describe("HTMLExport", () => {
716732
const file = getMessageFile(exporter);
717733
expect(file).not.toBeUndefined();
718734
});
735+
736+
it("should not crash when exporting mentions", async () => {
737+
mockMessages(EVENT_MESSAGE, EVENT_MENTION);
738+
const exporter = new HTMLExporter(
739+
room,
740+
ExportType.LastNMessages,
741+
{
742+
attachmentsIncluded: false,
743+
maxSize: 1_024 * 1_024,
744+
numberOfMessages: 40,
745+
},
746+
() => {},
747+
);
748+
749+
await exporter.export();
750+
751+
const file = getMessageFile(exporter);
752+
expect(file).not.toBeUndefined();
753+
});
719754
});

0 commit comments

Comments
 (0)