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

Commit

Permalink
add Ended poll text to ended poll reply formatted body (#10146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry authored Feb 13, 2023
1 parent 3eee91d commit b4565f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/Reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 { PERMITTED_URL_SCHEMES } from "../HtmlUtils";
import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks";
Expand Down Expand Up @@ -110,6 +111,15 @@ export function getNestedReplyText(
};
}

if (M_POLL_END.matches(ev.getType())) {
return {
html:
`<mx-reply><blockquote><a href="${evLink}">In reply to</a> <a href="${userLink}">${mxid}</a>` +
`<br>Ended poll</blockquote></mx-reply>`,
body: `> <${mxid}>Ended poll\n\n`,
};
}

// This fallback contains text that is explicitly EN.
switch (msgtype) {
case MsgType.Text:
Expand Down
9 changes: 9 additions & 0 deletions test/Reply-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import { IContent, MatrixEvent, MsgType } from "matrix-js-sdk/src/matrix";
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
import { LocationAssetType, M_ASSET } from "matrix-js-sdk/src/@types/location";
import { M_POLL_END } from "matrix-js-sdk/src/@types/polls";

import {
getNestedReplyText,
Expand Down Expand Up @@ -149,6 +150,14 @@ But this is not
expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot();
});
});

it("should create the expected fallback text for poll end events", () => {
const event = makeTestEvent(M_POLL_END.name, {
body: "body",
});

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 @@ -44,3 +44,12 @@ exports[`Reply getNestedReplyText should create the expected fallback text for m
"html": "<mx-reply><blockquote><a href="$$permalink$$">In reply to</a> <a href="https://matrix.to/#/@user1:server">@user1:server</a><br>shared their live location.</blockquote></mx-reply>",
}
`;

exports[`Reply getNestedReplyText should create the expected fallback text for poll end events 1`] = `
{
"body": "> <@user1:server>Ended poll
",
"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>",
}
`;

0 comments on commit b4565f5

Please sign in to comment.