From 56f6c1ef464ee07017e41402a4d3c07c2fcc548d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Oct 2025 14:43:34 +0100 Subject: [PATCH] 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> --- src/utils/exportUtils/HtmlExport.tsx | 49 ++++++++++--------- .../utils/exportUtils/HTMLExport-test.ts | 35 +++++++++++++ 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index d8ded97ff5..20b7b681ac 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -30,6 +30,7 @@ import MatrixClientContext from "../../contexts/MatrixClientContext"; import getExportCSS from "./exportCSS"; import { textForEvent } from "../../TextForEvent"; import { haveRendererForEvent } from "../../events/EventTileFactory"; +import { SDKContext, SdkContextClass } from "../../contexts/SDKContext.ts"; import exportJS from "!!raw-loader!./exportJS"; @@ -267,29 +268,31 @@ export default class HTMLExporter extends Exporter { return (
- - false} - isTwelveHour={false} - last={false} - lastInSection={false} - permalinkCreator={this.permalinkCreator} - lastSuccessful={false} - isSelectedEvent={false} - showReactions={true} - layout={Layout.Group} - showReadReceipts={false} - getRelationsForEvent={this.getRelationsForEvent} - ref={ref} - /> - + + + false} + isTwelveHour={false} + last={false} + lastInSection={false} + permalinkCreator={this.permalinkCreator} + lastSuccessful={false} + isSelectedEvent={false} + showReactions={true} + layout={Layout.Group} + showReadReceipts={false} + getRelationsForEvent={this.getRelationsForEvent} + ref={ref} + /> + +
); diff --git a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts index 139ed83133..0ef71463bb 100644 --- a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts +++ b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts @@ -32,6 +32,7 @@ import HTMLExporter from "../../../../src/utils/exportUtils/HtmlExport"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; import { mediaFromMxc } from "../../../../src/customisations/Media"; import SettingsStore from "../../../../src/settings/SettingsStore"; +import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts"; jest.mock("jszip"); 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 @alex:example.org', + "m.mentions": { user_ids: ["@alex:example.org"] }, + }, +}; + describe("HTMLExport", () => { let client: jest.Mocked; let room: Room; @@ -96,6 +111,7 @@ describe("HTMLExport", () => { jest.setSystemTime(REPEATABLE_DATE); client = stubClient() as jest.Mocked; + SdkContextClass.instance.client = client; DMRoomMap.makeShared(client); room = new Room("!myroom:example.org", client, "@me:example.org"); @@ -716,4 +732,23 @@ describe("HTMLExport", () => { const file = getMessageFile(exporter); 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(); + }); });