Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace OCA\Talk;

use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RecordingService;
use OCA\Talk\Service\RoomService;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -245,28 +244,8 @@ public function getToken(): string {

public function getName(): string {
if ($this->type === self::TYPE_ONE_TO_ONE) {
if ($this->name === '') {
// TODO use DI
$participantService = Server::get(ParticipantService::class);
// Fill the room name with the participants for 1-to-1 conversations
$users = $participantService->getParticipantUserIds($this);
sort($users);
/** @var RoomService $roomService */
$roomService = Server::get(RoomService::class);
$roomService->setName($this, json_encode($users), '');
} elseif (!str_starts_with($this->name, '["')) {
// TODO use DI
$participantService = Server::get(ParticipantService::class);
// Not the json array, but the old fallback when someone left
$users = $participantService->getParticipantUserIds($this);
if (count($users) !== 2) {
$users[] = $this->name;
}
sort($users);
/** @var RoomService $roomService */
$roomService = Server::get(RoomService::class);
$roomService->setName($this, json_encode($users), '');
}
// TODO use DI
Server::get(RoomService::class)->resolveOneToOneName($this, $this->name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now we already create the RoomService while before it was only needed if the name was not fixed already, which it was for everything that got ever rendered/created after Nextcloud 20

}
return $this->name;
}
Expand Down
16 changes: 16 additions & 0 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,22 @@ public function setRecordingConsent(Room $room, int $recordingConsent, bool $all
}
}

public function resolveOneToOneName(Room $room, string $currentName): void {
if ($currentName === '') {
$users = $this->participantService->getParticipantUserIds($room);
sort($users);
$this->setName($room, json_encode($users), '');
} elseif (!str_starts_with($currentName, '["')) {
// Legacy format: plain string (other user's ID), not a JSON array
$users = $this->participantService->getParticipantUserIds($room);
if (count($users) !== 2) {
$users[] = $currentName;
}
sort($users);
$this->setName($room, json_encode($users), '');
}
}

/**
* @throws NameException
*/
Expand Down
Loading