summaryrefslogtreecommitdiffstats
path: root/lib/Controller/RoomController.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-12-12 13:05:01 +0100
committerJoas Schilling <coding@schilljs.com>2023-01-04 17:35:21 +0100
commitc87813021c95b24bbc4503ecb5a2d00bf7ed8c87 (patch)
tree68ba969266c813de97f7d90add83714a4acc2ab7 /lib/Controller/RoomController.php
parent616a0cb202cffbea53da7b5a8f1bfed97ef70af7 (diff)
Allow creating individual breakout rooms via the normal API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/RoomController.php')
-rw-r--r--lib/Controller/RoomController.php54
1 files changed, 45 insertions, 9 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index e66aff032..5b4e71e89 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -657,7 +657,7 @@ class RoomController extends AEnvironmentAwareController {
* @param string $source
* @return DataResponse
*/
- public function createRoom(int $roomType, string $invite = '', string $roomName = '', string $source = ''): DataResponse {
+ public function createRoom(int $roomType, string $invite = '', string $roomName = '', string $source = '', string $objectType = '', string $objectId = ''): DataResponse {
if ($roomType !== Room::TYPE_ONE_TO_ONE) {
/** @var IUser $user */
$user = $this->userManager->get($this->userId);
@@ -672,7 +672,7 @@ class RoomController extends AEnvironmentAwareController {
return $this->createOneToOneRoom($invite);
case Room::TYPE_GROUP:
if ($invite === '') {
- return $this->createEmptyRoom($roomName, false);
+ return $this->createEmptyRoom($roomName, false, $objectType, $objectId);
}
if ($source === 'circles') {
return $this->createCircleRoom($invite);
@@ -795,27 +795,63 @@ class RoomController extends AEnvironmentAwareController {
/**
* @NoAdminRequired
- *
- * @param string $roomName
- * @param bool $public
- * @return DataResponse
*/
- protected function createEmptyRoom(string $roomName, bool $public = true): DataResponse {
+ protected function createEmptyRoom(string $roomName, bool $public = true, string $objectType = '', string $objectId = ''): DataResponse {
$currentUser = $this->userManager->get($this->userId);
if (!$currentUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$roomType = $public ? Room::TYPE_PUBLIC : Room::TYPE_GROUP;
+ /** @var Room|null $parentRoom */
+ $parentRoom = null;
+
+ if ($objectType === BreakoutRoom::PARENT_OBJECT_TYPE) {
+ try {
+ $parentRoom = $this->manager->getRoomForUserByToken($objectId, $this->userId);
+ $parentRoomParticipant = $this->participantService->getParticipant($parentRoom, $this->userId);
+
+ if (!$parentRoomParticipant->hasModeratorPermissions()) {
+ return new DataResponse(['error' => 'permissions'], Http::STATUS_BAD_REQUEST);
+ }
+ if ($parentRoom->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) {
+ return new DataResponse(['error' => 'mode'], Http::STATUS_BAD_REQUEST);
+ }
+
+ // Overwriting the type with the parent type.
+ $roomType = $parentRoom->getType();
+ } catch (RoomNotFoundException $e) {
+ return new DataResponse(['error' => 'room'], Http::STATUS_BAD_REQUEST);
+ } catch (ParticipantNotFoundException $e) {
+ return new DataResponse(['error' => 'permissions'], Http::STATUS_BAD_REQUEST);
+ }
+ }
// Create the room
try {
- $room = $this->roomService->createConversation($roomType, $roomName, $currentUser);
+ $room = $this->roomService->createConversation($roomType, $roomName, $currentUser, $objectType, $objectId);
} catch (InvalidArgumentException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
- return new DataResponse($this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED);
+ $currentParticipant = $this->participantService->getParticipant($room, $currentUser->getUID(), false);
+ if ($objectType === BreakoutRoom::PARENT_OBJECT_TYPE) {
+ // Enforce the lobby state when breakout rooms are disabled
+ if ($parentRoom instanceof Room && $parentRoom->getBreakoutRoomStatus() === BreakoutRoom::STATUS_STOPPED) {
+ $this->roomService->setLobby($room, Webinary::LOBBY_NON_MODERATORS, null, false, false);
+ }
+
+ $participants = $this->participantService->getParticipantsForRoom($parentRoom);
+ $moderators = array_filter($participants, static function (Participant $participant) use ($currentParticipant) {
+ return $participant->hasModeratorPermissions()
+ && $participant->getAttendee()->getId() !== $currentParticipant->getAttendee()->getId();
+ });
+ if (!empty($moderators)) {
+ $this->breakoutRoomService->addModeratorsToBreakoutRooms([$room], $moderators);
+ }
+ }
+
+ return new DataResponse($this->formatRoom($room, $currentParticipant), Http::STATUS_CREATED);
}
/**