Skip to content

Commit 340a635

Browse files
Merge pull request #14342 from nextcloud/backport/14270/stable29
[stable29] feat(chat): Add the mention id to parameters for easier editing
2 parents 6778a8f + 2b5b187 commit 340a635

20 files changed

+193
-145
lines changed

lib/Chat/Parser/SystemMessage.php

+5
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ protected function getUser(string $uid): array {
911911
'type' => 'user',
912912
'id' => $uid,
913913
'name' => $this->displayNames[$uid],
914+
'mention-id' => $uid,
914915
];
915916
}
916917

@@ -928,6 +929,7 @@ protected function getRemoteUser(Room $room, string $federationId): array {
928929
'id' => $cloudId->getUser(),
929930
'name' => $displayName,
930931
'server' => $cloudId->getRemote(),
932+
'mention-id' => 'federated_user/' . $cloudId->getUser() . '@' . $cloudId->getRemote(),
931933
];
932934
}
933935

@@ -949,6 +951,7 @@ protected function getGroup(string $gid): array {
949951
'type' => 'group',
950952
'id' => $gid,
951953
'name' => $this->groupNames[$gid],
954+
'mention-id' => 'user-group/' . $gid,
952955
];
953956
}
954957

@@ -982,6 +985,7 @@ protected function getCircle(string $circleId): array {
982985
'id' => $circleId,
983986
'name' => $this->circleNames[$circleId],
984987
'url' => $this->circleLinks[$circleId],
988+
'mention-id' => 'team/' . $circleId,
985989
];
986990
}
987991

@@ -1029,6 +1033,7 @@ protected function getGuest(Room $room, string $actorType, string $actorId): arr
10291033
'type' => 'guest',
10301034
'id' => 'guest/' . $actorId,
10311035
'name' => $this->guestNames[$key],
1036+
'mention-id' => 'guest/' . $actorId,
10321037
];
10331038
}
10341039

lib/Chat/Parser/UserMention.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ protected function parseMessage(Message $chatMessage): void {
165165
'name' => $chatMessage->getRoom()->getDisplayName($userId, true),
166166
'call-type' => $this->getRoomType($chatMessage->getRoom()),
167167
'icon-url' => $this->avatarService->getAvatarUrl($chatMessage->getRoom()),
168+
'mention-id' => $search,
168169
];
169170
} elseif ($mention['type'] === 'guest') {
170171
try {
@@ -178,6 +179,7 @@ protected function parseMessage(Message $chatMessage): void {
178179
'type' => $mention['type'],
179180
'id' => $mention['id'],
180181
'name' => $displayName,
182+
'mention-id' => $search,
181183
];
182184
} elseif ($mention['type'] === 'federated_user') {
183185
try {
@@ -197,7 +199,8 @@ protected function parseMessage(Message $chatMessage): void {
197199
'type' => 'user',
198200
'id' => $cloudId->getUser(),
199201
'name' => $displayName,
200-
'server' => $cloudId->getRemote()
202+
'server' => $cloudId->getRemote(),
203+
'mention-id' => $search,
201204
];
202205
} elseif ($mention['type'] === 'group') {
203206
$group = $this->groupManager->get($mention['id']);
@@ -211,6 +214,7 @@ protected function parseMessage(Message $chatMessage): void {
211214
'type' => 'user-group',
212215
'id' => $mention['id'],
213216
'name' => $displayName,
217+
'mention-id' => $search,
214218
];
215219
} else {
216220
try {
@@ -225,6 +229,7 @@ protected function parseMessage(Message $chatMessage): void {
225229
'type' => $mention['type'],
226230
'id' => $mention['id'],
227231
'name' => $displayName,
232+
'mention-id' => $search,
228233
];
229234
}
230235
}

lib/Federation/Proxy/TalkV1/UserConverter.php

+21
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ protected function convertMessageParameter(Room $room, array $parameter): array
101101
if ($parameter['type'] === 'user') { // RichObjectDefinition, not Attendee::ACTOR_USERS
102102
if (!isset($parameter['server'])) {
103103
$parameter['server'] = $room->getRemoteServer();
104+
if (!isset($parameter['mention-id'])) {
105+
$parameter['mention-id'] = $parameter['id'];
106+
}
104107
} elseif ($parameter['server']) {
105108
$localParticipants = $this->getLocalParticipants($room);
106109
$cloudId = $this->createCloudIdFromUserIdAndFullServerUrl($parameter['id'], $parameter['server']);
110+
if (!isset($parameter['mention-id'])) {
111+
$parameter['mention-id'] = 'federated_user/' . $parameter['id'] . '@' . $parameter['server'];
112+
}
107113
if (isset($localParticipants[$cloudId])) {
108114
unset($parameter['server']);
109115
$parameter['name'] = $localParticipants[$cloudId]['displayName'];
@@ -112,6 +118,21 @@ protected function convertMessageParameter(Room $room, array $parameter): array
112118
} elseif ($parameter['type'] === 'call' && $parameter['id'] === $room->getRemoteToken()) {
113119
$parameter['id'] = $room->getToken();
114120
$parameter['icon-url'] = $this->avatarService->getAvatarUrl($room);
121+
if (!isset($parameter['mention-id'])) {
122+
$parameter['mention-id'] = 'all';
123+
}
124+
} elseif ($parameter['type'] === 'circle') {
125+
if (!isset($parameter['mention-id'])) {
126+
$parameter['mention-id'] = 'team/' . $parameter['id'];
127+
}
128+
} elseif ($parameter['type'] === 'user-group') {
129+
if (!isset($parameter['mention-id'])) {
130+
$parameter['mention-id'] = 'group/' . $parameter['id'];
131+
}
132+
} elseif ($parameter['type'] === 'email' || $parameter['type'] === 'guest') {
133+
if (!isset($parameter['mention-id'])) {
134+
$parameter['mention-id'] = $parameter['type'] . '/' . $parameter['id'];
135+
}
115136
}
116137
return $parameter;
117138
}

tests/integration/features/callapi/notifications.feature

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Feature: callapi/notifications
2929
Given user "participant1" joins call "room" with 200 (v4)
3030
Then user "participant2" sees the following system messages in room "room" with 200
3131
| room | actorType | actorId | systemMessage | message | silent | messageParameters |
32-
| room | users | participant1 | call_started | {actor} started a call | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
33-
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} |
34-
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
32+
| room | users | participant1 | call_started | {actor} started a call | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
33+
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"},"user":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} |
34+
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
3535
Then user "participant2" has the following notifications
3636
| app | object_type | object_id | subject |
3737
| spreed | call | room | A group call has started in room |
@@ -51,9 +51,9 @@ Feature: callapi/notifications
5151
| silent | true |
5252
Then user "participant2" sees the following system messages in room "room" with 200
5353
| room | actorType | actorId | systemMessage | message | silent | messageParameters |
54-
| room | users | participant1 | call_started | {actor} started a silent call | true | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
55-
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} |
56-
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
54+
| room | users | participant1 | call_started | {actor} started a silent call | true | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
55+
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"},"user":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} |
56+
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
5757
Then user "participant2" has the following notifications
5858
| app | object_type | object_id | subject |
5959
Given user "participant1" leaves call "room" with 200 (v4)

0 commit comments

Comments
 (0)