Skip to content

Commit

Permalink
feat(chat): Add the mention id to parameters for easier editing
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 5, 2025
1 parent a10955b commit ee0074e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
9 changes: 8 additions & 1 deletion lib/Chat/Parser/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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']);
Expand All @@ -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']);
Expand All @@ -236,6 +241,7 @@ protected function parseMessage(Message $chatMessage): void {
'type' => $mention['type'],
'id' => $mention['id'],
'name' => $displayName,
'mention-id' => $search,
];
}
}
Expand Down Expand Up @@ -293,6 +299,7 @@ protected function getCircle(string $circleId): array {
'id' => $circleId,
'name' => $this->circleNames[$circleId],
'link' => $this->circleLinks[$circleId],
'mention-id' => 'team/' . $circleId,
];
}

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/features/chat-1/edit-message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/features/chat-4/rich-messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"}} |
32 changes: 23 additions & 9 deletions tests/php/Chat/Parser/UserMentionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
];

Expand Down Expand Up @@ -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',
]
];

Expand Down Expand Up @@ -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,
],
];

Expand Down Expand Up @@ -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',
]
];

Expand Down Expand Up @@ -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',
]
];

Expand Down Expand Up @@ -382,7 +390,8 @@ public function testGetRichMessageWhenDisplayNameCanNotBeResolved(): void {
'mention-user1' => [
'type' => 'user',
'id' => 'testUser',
'name' => ''
'name' => '',
'mention-id' => 'testUser',
]
];

Expand Down Expand Up @@ -430,6 +439,7 @@ public function testGetRichMessageWithAtAll(): void {
'name' => 'name',
'call-type' => 'group',
'icon-url' => 'getAvatarUrl',
'mention-id' => 'all',
]
];

Expand Down Expand Up @@ -471,6 +481,7 @@ public function testGetRichMessageWithFederatedUserMention(): void {
'id' => 'testUser',
'name' => 'Display Id',
'server' => 'example.tld',
'mention-id' => 'federated_user/[email protected]',
]
];

Expand Down Expand Up @@ -510,6 +521,7 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentioned(): void {
'type' => 'guest',
'id' => 'guest/123456',
'name' => 'Guest',
'mention-id' => 'guest/123456',
]
];

Expand Down Expand Up @@ -549,6 +561,7 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentionedMultipleTimes(
'type' => 'guest',
'id' => 'guest/123456',
'name' => 'Guest',
'mention-id' => 'guest/123456',
]
];

Expand Down Expand Up @@ -596,6 +609,7 @@ public function testGetRichMessageWhenAGuestWithANameIsMentionedMultipleTimes():
'type' => 'guest',
'id' => 'guest/abcdef',
'name' => 'Name',
'mention-id' => 'guest/abcdef',
]
];

Expand Down

0 comments on commit ee0074e

Please sign in to comment.