Skip to content

Commit

Permalink
feat(federation): Allow to convert a single type and id
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 6, 2024
1 parent 81008aa commit 8a823da
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/Federation/Proxy/TalkV1/UserConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 8a823da

Please sign in to comment.