From 8a823da8c04a7a3e2abf6c2a9aef191ff68adb05 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Mar 2024 12:31:22 +0100 Subject: [PATCH] feat(federation): Allow to convert a single type and id Signed-off-by: Joas Schilling --- lib/Federation/Proxy/TalkV1/UserConverter.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Federation/Proxy/TalkV1/UserConverter.php b/lib/Federation/Proxy/TalkV1/UserConverter.php index debc018839ab..d58aa8e4004a 100644 --- a/lib/Federation/Proxy/TalkV1/UserConverter.php +++ b/lib/Federation/Proxy/TalkV1/UserConverter.php @@ -45,6 +45,26 @@ public function __construct( ) { } + /** + * @return array{type: string, id: string} + */ + public function convertTypeAndId(Room $room, string $type, string $id): array { + if ($type === Attendee::ACTOR_USERS) { + $type = Attendee::ACTOR_FEDERATED_USERS; + $id .= '@' . $room->getRemoteServer(); + } elseif ($type === Attendee::ACTOR_FEDERATED_USERS) { + $localParticipants = $this->getLocalParticipants($room); + if (isset($localParticipants[$id])) { + $local = $localParticipants[$id]; + + $type = Attendee::ACTOR_USERS; + $id = $local['userId']; + } + } + + return ['type' => $type, 'id' => $id]; + } + public function convertAttendee(Room $room, array $entry, string $typeField, string $idField, string $displayNameField): array { if (!isset($entry[$typeField])) { return $entry; @@ -89,7 +109,7 @@ protected function convertMessageParameter(Room $room, array $parameter): array return $parameter; } - protected function convertMessageParameters(Room $room, array $message): array { + public function convertMessageParameters(Room $room, array $message): array { $message['messageParameters'] = array_map( fn (array $message): array => $this->convertMessageParameter($room, $message), $message['messageParameters']