Strip mentions from forwarded messages (#30884)
* strip mentions from forwarded messages fixes element-hq/element-web#30883 * call attachMentions() for empty m.mentions in forwarded messages As there is no EditorModel, attachMentions() currently does nothing * fix lint and typecheck * update test "should be navigable using arrow keys" * update test "forwards pin drop event" add empty mentions to expected content * add doc to transformEvent() & elaborate on attachMentions() * add test "strips mentions from forwarded messages" * fix lint * update source of `attachMentions()` import --------- Co-authored-by: David Baker <dbkr@users.noreply.github.com>
This commit is contained in:
@@ -153,8 +153,9 @@ describe("ForwardDialog", () => {
|
||||
|
||||
await userEvent.keyboard("[Enter]");
|
||||
expect(mockClient.sendEvent).toHaveBeenCalledWith("A", "m.room.message", {
|
||||
body: "Hello world!",
|
||||
msgtype: "m.text",
|
||||
"body": "Hello world!",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -248,6 +249,37 @@ describe("ForwardDialog", () => {
|
||||
expect(secondButton.getAttribute("aria-disabled")).toBeFalsy();
|
||||
});
|
||||
|
||||
it("strips mentions from forwarded messages", async () => {
|
||||
const messageWithMention = mkEvent({
|
||||
type: "m.room.message",
|
||||
room: sourceRoom,
|
||||
user: "@bob:example.org",
|
||||
content: {
|
||||
"msgtype": "m.text",
|
||||
"body": "Hi @alice:example.org",
|
||||
"m.mentions": {
|
||||
user_ids: ["@alice:example.org"],
|
||||
},
|
||||
},
|
||||
event: true,
|
||||
});
|
||||
|
||||
const { container } = mountForwardDialog(messageWithMention);
|
||||
const roomId = "a";
|
||||
|
||||
// Click the send button.
|
||||
act(() => {
|
||||
const sendButton = container.querySelector(".mx_ForwardList_sendButton");
|
||||
fireEvent.click(sendButton!);
|
||||
});
|
||||
|
||||
// Expected content should have mentions empty.
|
||||
expect(mockClient.sendEvent).toHaveBeenCalledWith(roomId, messageWithMention.getType(), {
|
||||
...messageWithMention.getContent(),
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
describe("Location events", () => {
|
||||
// 14.03.2022 16:15
|
||||
const now = 1647270879403;
|
||||
@@ -357,11 +389,12 @@ describe("ForwardDialog", () => {
|
||||
|
||||
sendToFirstRoom(container);
|
||||
|
||||
expect(mockClient.sendEvent).toHaveBeenCalledWith(
|
||||
roomId,
|
||||
pinDropLocationEvent.getType(),
|
||||
pinDropLocationEvent.getContent(),
|
||||
);
|
||||
const expectedContent = {
|
||||
...pinDropLocationEvent.getContent(),
|
||||
"m.mentions": {}, // Add mentions (explicitly set to empty)
|
||||
};
|
||||
|
||||
expect(mockClient.sendEvent).toHaveBeenCalledWith(roomId, pinDropLocationEvent.getType(), expectedContent);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user