diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index ed85ba8d67f..053878886bc 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ -import { Direction, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; -import { MediaEventContent } from "matrix-js-sdk/src/types"; +import { Direction, MatrixEvent, Relations, Room } from "matrix-js-sdk/src/matrix"; +import { EventType, MediaEventContent, RelationType } from "matrix-js-sdk/src/types"; import { saveAs } from "file-saver"; import { logger } from "matrix-js-sdk/src/logger"; import sanitizeFilename from "sanitize-filename"; @@ -284,5 +284,13 @@ export default abstract class Exporter { return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype!); } + protected getRelationsForEvent = ( + eventId: string, + relationType: RelationType | string, + eventType: EventType | string, + ): Relations | undefined => { + return this.room.getUnfilteredTimelineSet().relations.getChildEventsForEvent(eventId, relationType, eventType); + }; + public abstract export(): Promise; } diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index 9a16a9e44b0..08e488e5ffe 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -288,9 +288,10 @@ export default class HTMLExporter extends Exporter { permalinkCreator={this.permalinkCreator} lastSuccessful={false} isSelectedEvent={false} - showReactions={false} + showReactions={true} layout={Layout.Group} showReadReceipts={false} + getRelationsForEvent={this.getRelationsForEvent} /> diff --git a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts index 7d57866fcdf..833494473da 100644 --- a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts +++ b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts @@ -7,19 +7,24 @@ Please see LICENSE files in the repository root for full details. */ import { + EventTimeline, + EventTimelineSet, EventType, IRoomEvent, MatrixClient, MatrixEvent, MsgType, + Relations, + RelationType, Room, RoomMember, RoomState, } from "matrix-js-sdk/src/matrix"; import fetchMock from "fetch-mock-jest"; import escapeHtml from "escape-html"; +import { RelationsContainer } from "matrix-js-sdk/src/models/relations-container"; -import { filterConsole, mkStubRoom, REPEATABLE_DATE, stubClient } from "../../../test-utils"; +import { filterConsole, mkReaction, mkStubRoom, REPEATABLE_DATE, stubClient } from "../../../test-utils"; import { ExportType, IExportOptions } from "../../../../src/utils/exportUtils/exportUtils"; import SdkConfig from "../../../../src/SdkConfig"; import HTMLExporter from "../../../../src/utils/exportUtils/HtmlExport"; @@ -587,4 +592,41 @@ describe("HTMLExport", () => { expect(await file.text()).toContain("testing testing"); expect(client.createMessagesRequest).not.toHaveBeenCalled(); }); + + it("should include reactions", async () => { + const firstMessage = new MatrixEvent(EVENT_MESSAGE); + const reaction = mkReaction(firstMessage); + + const relationsContainer = { + getRelations: jest.fn(), + getChildEventsForEvent: jest.fn(), + } as unknown as RelationsContainer; + const relations = new Relations(RelationType.Annotation, EventType.Reaction, client); + relations.addEvent(reaction); + relationsContainer.getChildEventsForEvent = jest.fn().mockReturnValue(relations); + + const timelineSet = { + relations: relationsContainer, + getLiveTimeline: () => timeline, + } as unknown as EventTimelineSet; + const timeline = new EventTimeline(timelineSet); + room.getUnfilteredTimelineSet = jest.fn().mockReturnValue(timelineSet); + mockMessages(EVENT_MESSAGE); + + const exporter = new HTMLExporter( + room, + ExportType.LastNMessages, + { + attachmentsIncluded: false, + maxSize: 1_024 * 1_024, + numberOfMessages: 40, + }, + () => {}, + ); + + await exporter.export(); + + const file = getMessageFile(exporter); + expect(await file.text()).toContain(reaction.getContent()["m.relates_to"]?.key); + }); });