Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add fallback for replies to Polls #10380

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/utils/Reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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:
`<mx-reply><blockquote><a href="${evLink}">In reply to</a> <a href="${userLink}">${mxid}</a>` +
`<br>Poll: ${question}</blockquote></mx-reply>`,
body: `> <${mxid}> started poll: ${question}\n\n`,
};
}
if (M_POLL_END.matches(ev.getType())) {
return {
html:
Expand Down
8 changes: 7 additions & 1 deletion test/Reply-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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", () => {
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/Reply-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ exports[`Reply getNestedReplyText should create the expected fallback text for p
"html": "<mx-reply><blockquote><a href="$$permalink$$">In reply to</a> <a href="https://matrix.to/#/@user1:server">@user1:server</a><br>Ended poll</blockquote></mx-reply>",
}
`;

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": "<mx-reply><blockquote><a href="$$permalink$$">In reply to</a> <a href="https://matrix.to/#/@user:server.org">@user:server.org</a><br>Poll: Will this test pass?</blockquote></mx-reply>",
}
`;