Skip to content

Commit f85debf

Browse files
committed
feat(mention): Extend mention-id when proxying federated messages from old servers
Signed-off-by: Joas Schilling <[email protected]>
1 parent ee0074e commit f85debf

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Diff for: lib/Chat/Parser/SystemMessage.php

+5
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ protected function getUser(string $uid): array {
924924
'type' => 'user',
925925
'id' => $uid,
926926
'name' => $this->displayNames[$uid],
927+
'mention-id' => $uid,
927928
];
928929
}
929930

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

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

@@ -995,6 +998,7 @@ protected function getCircle(string $circleId): array {
995998
'id' => $circleId,
996999
'name' => $this->circleNames[$circleId],
9971000
'link' => $this->circleLinks[$circleId],
1001+
'mention-id' => 'team/' . $circleId,
9981002
];
9991003
}
10001004

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

Diff for: lib/Federation/Proxy/TalkV1/UserConverter.php

+21
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ protected function convertMessageParameter(Room $room, array $parameter): array
8585
if ($parameter['type'] === 'user') { // RichObjectDefinition, not Attendee::ACTOR_USERS
8686
if (!isset($parameter['server'])) {
8787
$parameter['server'] = $room->getRemoteServer();
88+
if (!isset($parameter['mention-id'])) {
89+
$parameter['mention-id'] = $parameter['id'];
90+
}
8891
} elseif ($parameter['server']) {
8992
$localParticipants = $this->getLocalParticipants($room);
9093
$cloudId = $this->createCloudIdFromUserIdAndFullServerUrl($parameter['id'], $parameter['server']);
94+
if (!isset($parameter['mention-id'])) {
95+
$parameter['mention-id'] = 'federated_user/' . $parameter['id'] . '@' . $parameter['server'];
96+
}
9197
if (isset($localParticipants[$cloudId])) {
9298
unset($parameter['server']);
9399
$parameter['name'] = $localParticipants[$cloudId]['displayName'];
@@ -96,6 +102,21 @@ protected function convertMessageParameter(Room $room, array $parameter): array
96102
} elseif ($parameter['type'] === 'call' && $parameter['id'] === $room->getRemoteToken()) {
97103
$parameter['id'] = $room->getToken();
98104
$parameter['icon-url'] = $this->avatarService->getAvatarUrl($room);
105+
if (!isset($parameter['mention-id'])) {
106+
$parameter['mention-id'] = 'all';
107+
}
108+
} elseif ($parameter['type'] === 'circle') {
109+
if (!isset($parameter['mention-id'])) {
110+
$parameter['mention-id'] = 'team/' . $parameter['id'];
111+
}
112+
} elseif ($parameter['type'] === 'user-group') {
113+
if (!isset($parameter['mention-id'])) {
114+
$parameter['mention-id'] = 'group/' . $parameter['id'];
115+
}
116+
} elseif ($parameter['type'] === 'email' || $parameter['type'] === 'guest') {
117+
if (!isset($parameter['mention-id'])) {
118+
$parameter['mention-id'] = $parameter['type'] . '/' . $parameter['id'];
119+
}
99120
}
100121
return $parameter;
101122
}

Diff for: tests/integration/features/federation/chat.feature

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ Feature: federation/chat
130130
And user "participant2" deletes message "Message 1-1 - Edit 1" from room "LOCAL::room" with 200
131131
Then user "participant1" sees the following messages in room "room" with 200
132132
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
133-
| 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 |
134-
| room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | |
133+
| 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 |
134+
| room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} | |
135135
When next message request has the following parameters set
136136
| timeout | 0 |
137137
And user "participant2" sees the following messages in room "LOCAL::room" with 200
138138
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
139-
| LOCAL::room | users | participant2 | participant2-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname"}} | Message deleted by author |
140-
| LOCAL::room | federated_users | participant1@{$LOCAL_URL} | participant1-displayname | Message deleted by author | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","server":"{$LOCAL_URL}"}} | |
139+
| 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 |
140+
| 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}"}} | |
141141
# Disabled due to https://github.com/nextcloud/spreed/issues/12957
142142
# Then user "participant2" is participant of the following rooms (v4)
143143
# | id | type | lastMessage |

0 commit comments

Comments
 (0)