diff --git a/src/utils/Reply.ts b/src/utils/Reply.ts index 14ff4058e1..dc3e8da2a3 100644 --- a/src/utils/Reply.ts +++ b/src/utils/Reply.ts @@ -21,7 +21,8 @@ import escapeHtml from "escape-html"; import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { MsgType } from "matrix-js-sdk/src/@types/event"; import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon"; -import { M_POLL_END } from "matrix-js-sdk/src/@types/polls"; +import { M_POLL_END, M_POLL_START } from "matrix-js-sdk/src/@types/polls"; +import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent"; import { PERMITTED_URL_SCHEMES } from "../HtmlUtils"; import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks"; @@ -112,6 +113,16 @@ export function getNestedReplyText( }; } + if (M_POLL_START.matches(ev.getType())) { + const extensibleEvent = ev.unstableExtensibleEvent as PollStartEvent; + const question = extensibleEvent?.question?.text; + return { + html: + `
In reply to ${mxid}` + + `
Poll: ${question}
`, + body: `> <${mxid}> started poll: ${question}\n\n`, + }; + } if (M_POLL_END.matches(ev.getType())) { return { html: diff --git a/test/Reply-test.ts b/test/Reply-test.ts index 358e34e540..48fc03d590 100644 --- a/test/Reply-test.ts +++ b/test/Reply-test.ts @@ -26,7 +26,7 @@ import { stripHTMLReply, stripPlainReply, } from "../src/utils/Reply"; -import { mkEvent } from "./test-utils"; +import { makePollStartEvent, mkEvent } from "./test-utils"; import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks"; function makeTestEvent(type: string, content: IContent): MatrixEvent { @@ -160,6 +160,12 @@ But this is not expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot(); }); + + it("should create the expected fallback text for poll start events", () => { + const event = makePollStartEvent("Will this test pass?", "@user:server.org"); + + expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot(); + }); }); describe("shouldDisplayReply", () => { diff --git a/test/__snapshots__/Reply-test.ts.snap b/test/__snapshots__/Reply-test.ts.snap index 6822f82f7e..242366574d 100644 --- a/test/__snapshots__/Reply-test.ts.snap +++ b/test/__snapshots__/Reply-test.ts.snap @@ -53,3 +53,12 @@ exports[`Reply getNestedReplyText should create the expected fallback text for p "html": "
In reply to @user1:server
Ended poll
", } `; + +exports[`Reply getNestedReplyText should create the expected fallback text for poll start events 1`] = ` +{ + "body": "> <@user:server.org> started poll: Will this test pass? + +", + "html": "
In reply to @user:server.org
Poll: Will this test pass?
", +} +`;