diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-22 12:35:28 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-30 12:38:09 +0300 |
commit | 542c3792207c5a70ccdefc80f882b23c660cc9d8 (patch) | |
tree | dfb6e8e633c30772e63dd55870f03a13b114c9f9 /lib/Service | |
parent | b76b92fb931748326974e95fbfd329812cd42f49 (diff) |
Further adjustments in the RoomController
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/ParticipantService.php | 27 | ||||
-rw-r--r-- | lib/Service/RoomService.php | 20 |
2 files changed, 39 insertions, 8 deletions
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 17ee86dc5..6f97eb562 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -43,6 +43,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IUser; +use OCP\IUserManager; use OCP\Security\ISecureRandom; class ParticipantService { @@ -58,19 +59,23 @@ class ParticipantService { protected $connection; /** @var IEventDispatcher */ private $dispatcher; + /** @var IUserManager */ + private $userManager; public function __construct(AttendeeMapper $attendeeMapper, SessionMapper $sessionMapper, SessionService $sessionService, ISecureRandom $secureRandom, IDBConnection $connection, - IEventDispatcher $dispatcher) { + IEventDispatcher $dispatcher, + IUserManager $userManager) { $this->attendeeMapper = $attendeeMapper; $this->sessionMapper = $sessionMapper; $this->sessionService = $sessionService; $this->secureRandom = $secureRandom; $this->connection = $connection; $this->dispatcher = $dispatcher; + $this->userManager = $userManager; } public function updateParticipantType(Room $room, Participant $participant, int $participantType): void { @@ -206,6 +211,26 @@ class ParticipantService { $this->dispatcher->dispatch(Room::EVENT_AFTER_USERS_ADD, $event); } + public function ensureOneToOneRoomIsFilled(Room $room): void { + if ($room->getType() !== Room::ONE_TO_ONE_CALL) { + return; + } + + $users = json_decode($room->getName(), true); + $participants = $room->getParticipantUserIds(); + $missingUsers = array_diff($users, $participants); + + foreach ($missingUsers as $userId) { + if ($this->userManager->userExists($userId)) { + $this->addUsers($room, [[ + 'actorType' => 'users', + 'actorId' => $userId, + 'participantType' => Participant::OWNER, + ]]); + } + } + } + public function leaveRoomAsSession(Room $room, Participant $participant): void { if (!$participant->isGuest()) { $event = new ParticipantEvent($room, $participant); diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index c3fcec059..69ade564d 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -57,17 +57,23 @@ class RoomService { try { // If room exists: Reuse that one, otherwise create a new one. $room = $this->manager->getOne2OneRoom($actor->getUID(), $targetUser->getUID()); - $room->ensureOneToOneRoomIsFilled(); + $this->participantService->ensureOneToOneRoomIsFilled($room); } catch (RoomNotFoundException $e) { $users = [$actor->getUID(), $targetUser->getUID()]; sort($users); $room = $this->manager->createRoom(Room::ONE_TO_ONE_CALL, json_encode($users)); - $room->addUsers([ - 'userId' => $actor->getUID(), - 'participantType' => Participant::OWNER, - ], [ - 'userId' => $targetUser->getUID(), - 'participantType' => Participant::OWNER, + + $this->participantService->addUsers($room, [ + [ + 'actorType' => 'users', + 'actorId' => $actor->getUID(), + 'participantType' => Participant::OWNER, + ], + [ + 'actorType' => 'users', + 'actorId' => $targetUser->getUID(), + 'participantType' => Participant::OWNER, + ], ]); } |