diff options
author | Joas Schilling <coding@schilljs.com> | 2023-01-30 14:43:13 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-01-30 14:58:25 +0100 |
commit | 641f5ca6965db27fda7ec3699d3aabc0526ba59d (patch) | |
tree | 9a241a73681fc2377a1cccd66a6530e2738ce3d6 /lib/Controller | |
parent | 8225b4443b5678c1034757d6b5a989054e4377f4 (diff) |
Return the rooms when possible
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/BreakoutRoomController.php | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/lib/Controller/BreakoutRoomController.php b/lib/Controller/BreakoutRoomController.php index 161ec1aff..fef7a6732 100644 --- a/lib/Controller/BreakoutRoomController.php +++ b/lib/Controller/BreakoutRoomController.php @@ -26,7 +26,10 @@ declare(strict_types=1); namespace OCA\Talk\Controller; use InvalidArgumentException; +use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Service\BreakoutRoomService; +use OCA\Talk\Service\ParticipantService; +use OCA\Talk\Service\RoomFormatter; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\Comments\MessageTooLongException; @@ -37,6 +40,9 @@ class BreakoutRoomController extends AEnvironmentAwareController { string $appName, IRequest $request, protected BreakoutRoomService $breakoutRoomService, + protected ParticipantService $participantService, + protected RoomFormatter $roomFormatter, + protected ?string $userId, ) { parent::__construct($appName, $request); } @@ -52,13 +58,13 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function configureBreakoutRooms(int $mode, int $amount, string $attendeeMap = '[]'): DataResponse { try { - $this->breakoutRoomService->setupBreakoutRooms($this->room, $mode, $amount, $attendeeMap); + $rooms = $this->breakoutRoomService->setupBreakoutRooms($this->room, $mode, $amount, $attendeeMap); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - // FIXME make a useful response? - return new DataResponse(); + $rooms[] = $this->room; + return new DataResponse($this->formatMultipleRooms($rooms), Http::STATUS_OK); } /** @@ -67,7 +73,13 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function removeBreakoutRooms(): DataResponse { $this->breakoutRoomService->removeBreakoutRooms($this->room); - return new DataResponse(); + + return new DataResponse($this->roomFormatter->formatRoom( + $this->getResponseFormat(), + [], + $this->room, + $this->participant, + )); } /** @@ -76,13 +88,14 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function broadcastChatMessage(string $message): DataResponse { try { - $this->breakoutRoomService->broadcastChatMessage($this->room, $this->participant, $message); + $rooms = $this->breakoutRoomService->broadcastChatMessage($this->room, $this->participant, $message); } catch (MessageTooLongException $e) { return new DataResponse(['error' => 'message'], Http::STATUS_REQUEST_ENTITY_TOO_LARGE); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse([], Http::STATUS_CREATED); + $rooms[] = $this->room; + return new DataResponse($this->formatMultipleRooms($rooms), Http::STATUS_CREATED); } /** @@ -91,18 +104,17 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function applyAttendeeMap(string $attendeeMap): DataResponse { try { - $this->breakoutRoomService->applyAttendeeMap($this->room, $attendeeMap); + $rooms = $this->breakoutRoomService->applyAttendeeMap($this->room, $attendeeMap); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse([], Http::STATUS_OK); + $rooms[] = $this->room; + return new DataResponse($this->formatMultipleRooms($rooms), Http::STATUS_OK); } /** * @NoAdminRequired * @RequireLoggedInParticipant - * - * @return DataResponse */ public function requestAssistance(): DataResponse { try { @@ -111,14 +123,17 @@ class BreakoutRoomController extends AEnvironmentAwareController { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse(); + return new DataResponse($this->roomFormatter->formatRoom( + $this->getResponseFormat(), + [], + $this->room, + $this->participant, + )); } /** * @NoAdminRequired * @RequireLoggedInParticipant - * - * @return DataResponse */ public function resetRequestForAssistance(): DataResponse { try { @@ -127,7 +142,12 @@ class BreakoutRoomController extends AEnvironmentAwareController { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse(); + return new DataResponse($this->roomFormatter->formatRoom( + $this->getResponseFormat(), + [], + $this->room, + $this->participant, + )); } /** @@ -136,12 +156,13 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function startBreakoutRooms(): DataResponse { try { - $this->breakoutRoomService->startBreakoutRooms($this->room); + $rooms = $this->breakoutRoomService->startBreakoutRooms($this->room); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse(); + $rooms[] = $this->room; + return new DataResponse($this->formatMultipleRooms($rooms), Http::STATUS_OK); } /** @@ -150,12 +171,13 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function stopBreakoutRooms(): DataResponse { try { - $this->breakoutRoomService->stopBreakoutRooms($this->room); + $rooms = $this->breakoutRoomService->stopBreakoutRooms($this->room); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse(); + $rooms[] = $this->room; + return new DataResponse($this->formatMultipleRooms($rooms), Http::STATUS_OK); } /** @@ -164,11 +186,32 @@ class BreakoutRoomController extends AEnvironmentAwareController { */ public function switchBreakoutRoom(string $target): DataResponse { try { - $this->breakoutRoomService->switchBreakoutRoom($this->room, $this->participant, $target); + $room = $this->breakoutRoomService->switchBreakoutRoom($this->room, $this->participant, $target); } catch (InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } - return new DataResponse(); + return new DataResponse($this->roomFormatter->formatRoom( + $this->getResponseFormat(), + [], + $room, + $this->participant, + )); + } + + protected function formatMultipleRooms(array $rooms): array { + $return = []; + foreach ($rooms as $room) { + try { + $return[] = $this->roomFormatter->formatRoom( + $this->getResponseFormat(), + [], + $room, + $this->participantService->getParticipant($room, $this->userId) + ); + } catch (ParticipantNotFoundException $e) { + } + } + return $return; } } |