From 8d654d66ef92e4ca6e594f942e04d5db7eebfc15 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 16 Oct 2024 18:57:09 +0300 Subject: [PATCH] Implement MSC4142: Remove unintentional intentional mentions in replies --- src/components/views/rooms/SendMessageComposer.tsx | 6 ------ .../components/views/rooms/EditMessageComposer-test.tsx | 2 -- .../components/views/rooms/SendMessageComposer-test.tsx | 4 ++-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 776963eb338..c96a6f5af82 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -100,12 +100,6 @@ export function attachMentions( // event + any mentioned users in that event. if (replyToEvent) { userMentions.add(replyToEvent.sender!.userId); - // TODO What do we do if the reply event *doeesn't* have this property? - // Try to fish out replies from the contents? - const userIds = replyToEvent.getContent()["m.mentions"]?.user_ids; - if (Array.isArray(userIds)) { - userIds.forEach((userId) => userMentions.add(userId)); - } } // If user provided content is available, check to see if any users are mentioned. diff --git a/test/unit-tests/components/views/rooms/EditMessageComposer-test.tsx b/test/unit-tests/components/views/rooms/EditMessageComposer-test.tsx index a34e2e895b1..1599f311a33 100644 --- a/test/unit-tests/components/views/rooms/EditMessageComposer-test.tsx +++ b/test/unit-tests/components/views/rooms/EditMessageComposer-test.tsx @@ -432,8 +432,6 @@ describe("", () => { user_ids: [ // sender of event we replied to originalEvent.getSender()!, - // mentions from this event - "@bob:server.org", ], }, }, diff --git a/test/unit-tests/components/views/rooms/SendMessageComposer-test.tsx b/test/unit-tests/components/views/rooms/SendMessageComposer-test.tsx index a41c221616a..b1edcd148b3 100644 --- a/test/unit-tests/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/unit-tests/components/views/rooms/SendMessageComposer-test.tsx @@ -196,7 +196,7 @@ describe("", () => { "m.mentions": { user_ids: ["@bob:test"] }, }); - // It also adds any other mentioned users, but removes yourself. + // It no longer adds any other mentioned users replyToEvent = mkEvent({ type: "m.room.message", user: "@bob:test", @@ -207,7 +207,7 @@ describe("", () => { content = {}; attachMentions("@alice:test", content, model, replyToEvent); expect(content).toEqual({ - "m.mentions": { user_ids: ["@bob:test", "@charlie:test"] }, + "m.mentions": { user_ids: ["@bob:test"] }, }); });