Skip to content

Commit 5211b62

Browse files
author
Kerry
authored
add fallback reply for poll start (matrix-org#10380)
1 parent a86a8e7 commit 5211b62

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/utils/Reply.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import escapeHtml from "escape-html";
2121
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
2222
import { MsgType } from "matrix-js-sdk/src/@types/event";
2323
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
24-
import { M_POLL_END } from "matrix-js-sdk/src/@types/polls";
24+
import { M_POLL_END, M_POLL_START } from "matrix-js-sdk/src/@types/polls";
25+
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
2526

2627
import { PERMITTED_URL_SCHEMES } from "../HtmlUtils";
2728
import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks";
@@ -112,6 +113,16 @@ export function getNestedReplyText(
112113
};
113114
}
114115

116+
if (M_POLL_START.matches(ev.getType())) {
117+
const extensibleEvent = ev.unstableExtensibleEvent as PollStartEvent;
118+
const question = extensibleEvent?.question?.text;
119+
return {
120+
html:
121+
`<mx-reply><blockquote><a href="${evLink}">In reply to</a> <a href="${userLink}">${mxid}</a>` +
122+
`<br>Poll: ${question}</blockquote></mx-reply>`,
123+
body: `> <${mxid}> started poll: ${question}\n\n`,
124+
};
125+
}
115126
if (M_POLL_END.matches(ev.getType())) {
116127
return {
117128
html:

test/Reply-test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
stripHTMLReply,
2727
stripPlainReply,
2828
} from "../src/utils/Reply";
29-
import { mkEvent } from "./test-utils";
29+
import { makePollStartEvent, mkEvent } from "./test-utils";
3030
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
3131

3232
function makeTestEvent(type: string, content: IContent): MatrixEvent {
@@ -160,6 +160,12 @@ But this is not
160160

161161
expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot();
162162
});
163+
164+
it("should create the expected fallback text for poll start events", () => {
165+
const event = makePollStartEvent("Will this test pass?", "@user:server.org");
166+
167+
expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot();
168+
});
163169
});
164170

165171
describe("shouldDisplayReply", () => {

test/__snapshots__/Reply-test.ts.snap

+9
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ exports[`Reply getNestedReplyText should create the expected fallback text for p
5353
"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>",
5454
}
5555
`;
56+
57+
exports[`Reply getNestedReplyText should create the expected fallback text for poll start events 1`] = `
58+
{
59+
"body": "> <@user:server.org> started poll: Will this test pass?
60+
61+
",
62+
"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>",
63+
}
64+
`;

0 commit comments

Comments
 (0)