diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php index 233915f70b1..5d87b0c92fb 100644 --- a/lib/Chat/Parser/UserMention.php +++ b/lib/Chat/Parser/UserMention.php @@ -161,6 +161,7 @@ protected function parseMessage(Message $chatMessage): void { 'name' => $chatMessage->getRoom()->getDisplayName($userId, true), 'call-type' => $this->getRoomType($chatMessage->getRoom()), 'icon-url' => $this->avatarService->getAvatarUrl($chatMessage->getRoom()), + 'mention-id' => $search, ]; } elseif ($mention['type'] === 'guest') { try { @@ -174,6 +175,7 @@ protected function parseMessage(Message $chatMessage): void { 'type' => $mention['type'], 'id' => $mention['id'], 'name' => $displayName, + 'mention-id' => $search, ]; } elseif ($mention['type'] === 'email') { try { @@ -187,6 +189,7 @@ protected function parseMessage(Message $chatMessage): void { 'type' => $mention['type'], 'id' => $mention['id'], 'name' => $displayName, + 'mention-id' => $search, ]; } elseif ($mention['type'] === 'federated_user') { try { @@ -206,7 +209,8 @@ protected function parseMessage(Message $chatMessage): void { 'type' => 'user', 'id' => $cloudId->getUser(), 'name' => $displayName, - 'server' => $cloudId->getRemote() + 'server' => $cloudId->getRemote(), + 'mention-id' => $search, ]; } elseif ($mention['type'] === 'group') { $group = $this->groupManager->get($mention['id']); @@ -220,6 +224,7 @@ protected function parseMessage(Message $chatMessage): void { 'type' => 'user-group', 'id' => $mention['id'], 'name' => $displayName, + 'mention-id' => $search, ]; } elseif ($mention['type'] === 'team') { $messageParameters[$mentionParameterId] = $this->getCircle($mention['id']); @@ -236,6 +241,7 @@ protected function parseMessage(Message $chatMessage): void { 'type' => $mention['type'], 'id' => $mention['id'], 'name' => $displayName, + 'mention-id' => $search, ]; } } @@ -293,6 +299,7 @@ protected function getCircle(string $circleId): array { 'id' => $circleId, 'name' => $this->circleNames[$circleId], 'link' => $this->circleLinks[$circleId], + 'mention-id' => 'team/' . $circleId, ]; } diff --git a/tests/integration/features/chat-1/edit-message.feature b/tests/integration/features/chat-1/edit-message.feature index c6a1a79556d..30da38a510b 100644 --- a/tests/integration/features/chat-1/edit-message.feature +++ b/tests/integration/features/chat-1/edit-message.feature @@ -100,7 +100,7 @@ Feature: chat-1/edit-message And user "participant2" edits message "Message 1" in room "room" to "Message 1 - Edit @participant1" with 200 Then user "participant1" sees the following messages in room "room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | Then user "participant1" has the following notifications | app | object_type | object_id | subject | | spreed | chat | room/Message 1 - Edit {mention-user1} | participant2-displayname mentioned you in conversation room | @@ -160,7 +160,7 @@ Feature: chat-1/edit-message And user "participant2" sends message "Message 1 - @participant1" to room "room" with 201 Then user "participant1" sees the following messages in room "room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | room | users | participant2 | participant2-displayname | Message 1 - {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant2 | participant2-displayname | Message 1 - {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | Then user "participant1" has the following notifications | app | object_type | object_id | subject | | spreed | chat | room/Message 1 - {mention-user1} | participant2-displayname mentioned you in conversation room | @@ -180,7 +180,7 @@ Feature: chat-1/edit-message And user "participant2" edits message "Message 1 - @participant1" in room "room" to "Message 1 - Edit @participant1" with 200 Then user "participant1" sees the following messages in room "room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | Then user "participant1" has the following notifications | app | object_type | object_id | subject | | spreed | chat | room/Message 1 - Edit {mention-user1} | participant2-displayname mentioned you in conversation room | @@ -209,7 +209,7 @@ Feature: chat-1/edit-message And user "participant2" edits message "Message 1 - @all" in room "room" to "Message 1 - Edit @participant1" with 200 Then user "participant1" sees the following messages in room "room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant2 | participant2-displayname | Message 1 - Edit {mention-user1} | {"mention-user1":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | Then user "participant1" has the following notifications | app | object_type | object_id | subject | | spreed | chat | room/Message 1 - Edit {mention-user1} | participant2-displayname mentioned everyone in conversation room | diff --git a/tests/integration/features/chat-4/rich-messages.feature b/tests/integration/features/chat-4/rich-messages.feature index 8682eea2231..ecc28064d97 100644 --- a/tests/integration/features/chat-4/rich-messages.feature +++ b/tests/integration/features/chat-4/rich-messages.feature @@ -21,7 +21,7 @@ Feature: chat-2/rich-messages When user "participant1" sends message "Mention to @participant2" to room "public room" with 201 Then user "participant1" sees the following messages in room "public room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} | Scenario: message with mention to invalid user has mention parameter Given user "participant1" creates room "public room" (v4) @@ -39,7 +39,7 @@ Feature: chat-2/rich-messages When user "participant1" sends message "Mention to @participant2 and @participant2 again" to room "public room" with 201 Then user "participant1" sees the following messages in room "public room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} and {mention-user1} again | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} and {mention-user1} again | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} | Scenario: message with mentions to several users has mention parameters Given user "participant1" creates room "public room" (v4) @@ -48,7 +48,7 @@ Feature: chat-2/rich-messages When user "participant1" sends message "Mention to @participant2, @unknownUser, @participant2 again and @participant3" to room "public room" with 201 Then user "participant1" sees the following messages in room "public room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | public room | users | participant1 | participant1-displayname | Mention to {mention-user1}, @unknownUser, {mention-user1} again and {mention-user2} | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname"}} | + | public room | users | participant1 | participant1-displayname | Mention to {mention-user1}, @unknownUser, {mention-user1} again and {mention-user2} | {"mention-user1":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname","mention-id":"participant3"}} | Scenario: message with mentions of subname users (uid1 is fully part of uid2) Given user "participant1" creates room "public room" (v4) @@ -58,5 +58,5 @@ Feature: chat-2/rich-messages When user "participant1" sends message "Mention to @participant3a and @participant3" to room "public room" with 201 Then user "participant1" sees the following messages in room "public room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | - | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} and {mention-user2} | {"mention-user1":{"type":"user","id":"participant3a","name":"participant3a-displayname"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname"}} | - | public room | users | participant1 | participant1-displayname | Mention to {mention-user2} and {mention-user1} | {"mention-user1":{"type":"user","id":"participant3a","name":"participant3a-displayname"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname"}} | + | public room | users | participant1 | participant1-displayname | Mention to {mention-user1} and {mention-user2} | {"mention-user1":{"type":"user","id":"participant3a","name":"participant3a-displayname","mention-id":"participant3a"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname","mention-id":"participant3"}} | + | public room | users | participant1 | participant1-displayname | Mention to {mention-user2} and {mention-user1} | {"mention-user1":{"type":"user","id":"participant3a","name":"participant3a-displayname","mention-id":"participant3a"},"mention-user2":{"type":"user","id":"participant3","name":"participant3-displayname","mention-id":"participant3"}} | diff --git a/tests/php/Chat/Parser/UserMentionTest.php b/tests/php/Chat/Parser/UserMentionTest.php index ddf41310efe..cf1995ddbb7 100644 --- a/tests/php/Chat/Parser/UserMentionTest.php +++ b/tests/php/Chat/Parser/UserMentionTest.php @@ -133,7 +133,8 @@ public function testGetRichMessageWithSingleMention(): void { 'mention-user1' => [ 'type' => 'user', 'id' => 'testUser', - 'name' => 'testUser display name' + 'name' => 'testUser display name', + 'mention-id' => 'testUser', ] ]; @@ -172,7 +173,8 @@ public function testGetRichMessageWithDuplicatedMention(): void { 'mention-user1' => [ 'type' => 'user', 'id' => 'testUser', - 'name' => 'testUser display name' + 'name' => 'testUser display name', + 'mention-id' => 'testUser', ] ]; @@ -240,12 +242,14 @@ public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(strin 'mention-user1' => [ 'type' => 'user', 'id' => $longerId, - 'name' => $longerId . ' display name' + 'name' => $longerId . ' display name', + 'mention-id' => $longerId, ], 'mention-user2' => [ 'type' => 'user', 'id' => $baseId, - 'name' => $baseId . ' display name' + 'name' => $baseId . ' display name', + 'mention-id' => $baseId, ], ]; @@ -292,17 +296,20 @@ public function testGetRichMessageWithSeveralMentions(): void { 'mention-user1' => [ 'type' => 'user', 'id' => 'testUser1', - 'name' => 'testUser1 display name' + 'name' => 'testUser1 display name', + 'mention-id' => 'testUser1', ], 'mention-user2' => [ 'type' => 'user', 'id' => 'testUser2', - 'name' => 'testUser2 display name' + 'name' => 'testUser2 display name', + 'mention-id' => 'testUser2', ], 'mention-user3' => [ 'type' => 'user', 'id' => 'testUser3', - 'name' => 'testUser3 display name' + 'name' => 'testUser3 display name', + 'mention-id' => 'testUser3', ] ]; @@ -344,7 +351,8 @@ public function testGetRichMessageWithNonExistingUserMention(): void { 'mention-user1' => [ 'type' => 'user', 'id' => 'testUser', - 'name' => 'testUser display name' + 'name' => 'testUser display name', + 'mention-id' => 'testUser', ] ]; @@ -382,7 +390,8 @@ public function testGetRichMessageWhenDisplayNameCanNotBeResolved(): void { 'mention-user1' => [ 'type' => 'user', 'id' => 'testUser', - 'name' => '' + 'name' => '', + 'mention-id' => 'testUser', ] ]; @@ -430,6 +439,7 @@ public function testGetRichMessageWithAtAll(): void { 'name' => 'name', 'call-type' => 'group', 'icon-url' => 'getAvatarUrl', + 'mention-id' => 'all', ] ]; @@ -471,6 +481,7 @@ public function testGetRichMessageWithFederatedUserMention(): void { 'id' => 'testUser', 'name' => 'Display Id', 'server' => 'example.tld', + 'mention-id' => 'federated_user/testUser@example.tld', ] ]; @@ -510,6 +521,7 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentioned(): void { 'type' => 'guest', 'id' => 'guest/123456', 'name' => 'Guest', + 'mention-id' => 'guest/123456', ] ]; @@ -549,6 +561,7 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentionedMultipleTimes( 'type' => 'guest', 'id' => 'guest/123456', 'name' => 'Guest', + 'mention-id' => 'guest/123456', ] ]; @@ -596,6 +609,7 @@ public function testGetRichMessageWhenAGuestWithANameIsMentionedMultipleTimes(): 'type' => 'guest', 'id' => 'guest/abcdef', 'name' => 'Name', + 'mention-id' => 'guest/abcdef', ] ];