Skip to content

Commit

Permalink
feat(mention): Extend mention-id when proxying federated messages fro…
Browse files Browse the repository at this point in the history
…m old servers

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 6, 2025
1 parent ee0074e commit f85debf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ protected function getUser(string $uid): array {
'type' => 'user',
'id' => $uid,
'name' => $this->displayNames[$uid],
'mention-id' => $uid,
];
}

Expand All @@ -941,6 +942,7 @@ protected function getRemoteUser(Room $room, string $federationId): array {
'id' => $cloudId->getUser(),
'name' => $displayName,
'server' => $cloudId->getRemote(),
'mention-id' => 'federated_user/' . $cloudId->getUser() . '@' . $cloudId->getRemote(),
];
}

Expand All @@ -962,6 +964,7 @@ protected function getGroup(string $gid): array {
'type' => 'group',
'id' => $gid,
'name' => $this->groupNames[$gid],
'mention-id' => 'user-group/' . $gid,
];
}

Expand Down Expand Up @@ -995,6 +998,7 @@ protected function getCircle(string $circleId): array {
'id' => $circleId,
'name' => $this->circleNames[$circleId],
'link' => $this->circleLinks[$circleId],
'mention-id' => 'team/' . $circleId,
];
}

Expand Down Expand Up @@ -1042,6 +1046,7 @@ protected function getGuest(Room $room, string $actorType, string $actorId): arr
'type' => 'guest',
'id' => ($actorType === Attendee::ACTOR_GUESTS ? 'guest/' : 'email/') . $actorId,
'name' => $this->guestNames[$key],
'mention-id' => ($actorType === Attendee::ACTOR_GUESTS ? 'guest/' : 'email/') . $actorId,
];
}

Expand Down
21 changes: 21 additions & 0 deletions lib/Federation/Proxy/TalkV1/UserConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ protected function convertMessageParameter(Room $room, array $parameter): array
if ($parameter['type'] === 'user') { // RichObjectDefinition, not Attendee::ACTOR_USERS
if (!isset($parameter['server'])) {
$parameter['server'] = $room->getRemoteServer();
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = $parameter['id'];
}
} elseif ($parameter['server']) {
$localParticipants = $this->getLocalParticipants($room);
$cloudId = $this->createCloudIdFromUserIdAndFullServerUrl($parameter['id'], $parameter['server']);
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'federated_user/' . $parameter['id'] . '@' . $parameter['server'];
}
if (isset($localParticipants[$cloudId])) {
unset($parameter['server']);
$parameter['name'] = $localParticipants[$cloudId]['displayName'];
Expand All @@ -96,6 +102,21 @@ protected function convertMessageParameter(Room $room, array $parameter): array
} elseif ($parameter['type'] === 'call' && $parameter['id'] === $room->getRemoteToken()) {
$parameter['id'] = $room->getToken();
$parameter['icon-url'] = $this->avatarService->getAvatarUrl($room);
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'all';
}
} elseif ($parameter['type'] === 'circle') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'team/' . $parameter['id'];
}
} elseif ($parameter['type'] === 'user-group') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'group/' . $parameter['id'];
}
} elseif ($parameter['type'] === 'email' || $parameter['type'] === 'guest') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = $parameter['type'] . '/' . $parameter['id'];
}
}
return $parameter;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ Feature: federation/chat
And user "participant2" deletes message "Message 1-1 - Edit 1" from room "LOCAL::room" with 200
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | federated_users | participant2@{$LOCAL_REMOTE_URL} | participant2-displayname | Message deleted by author | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname","server":"{$LOCAL_REMOTE_URL}"}} | Message deleted by you |
| room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | |
| room | federated_users | participant2@{$LOCAL_REMOTE_URL} | participant2-displayname | Message deleted by author | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname","server":"{$LOCAL_REMOTE_URL}","mention-id":"federated_user\/participant2@{$LOCAL_REMOTE_URL}"}} | Message deleted by you |
| room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | |
When next message request has the following parameters set
| timeout | 0 |
And user "participant2" sees the following messages in room "LOCAL::room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| LOCAL::room | users | participant2 | participant2-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname"}} | Message deleted by author |
| LOCAL::room | federated_users | participant1@{$LOCAL_URL} | participant1-displayname | Message deleted by author | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","server":"{$LOCAL_URL}"}} | |
| LOCAL::room | users | participant2 | participant2-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"federated_user\/participant2@{$LOCAL_REMOTE_URL}"}} | Message deleted by author |
| LOCAL::room | federated_users | participant1@{$LOCAL_URL} | participant1-displayname | Message deleted by author | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1","server":"{$LOCAL_URL}"}} | |
# Disabled due to https://github.com/nextcloud/spreed/issues/12957
# Then user "participant2" is participant of the following rooms (v4)
# | id | type | lastMessage |
Expand Down

0 comments on commit f85debf

Please sign in to comment.