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 | |
parent | 8225b4443b5678c1034757d6b5a989054e4377f4 (diff) |
Return the rooms when possible
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | docs/breakout-rooms.md | 20 | ||||
-rw-r--r-- | lib/Controller/BreakoutRoomController.php | 83 | ||||
-rw-r--r-- | lib/Service/BreakoutRoomService.php | 44 |
3 files changed, 115 insertions, 32 deletions
diff --git a/docs/breakout-rooms.md b/docs/breakout-rooms.md index 4e1790e76..2e160f99c 100644 --- a/docs/breakout-rooms.md +++ b/docs/breakout-rooms.md @@ -35,6 +35,8 @@ Group and public conversations can be used to host breakout rooms. + `400 Bad Request` Error `attendeeMap`: When the attendee map contains an invalid room number or moderator + `403 Forbidden` When the current user is not a moderator/owner + `404 Not Found` When the conversation could not be found for the participant + - Data: Array of conversations (breakout rooms and parent) + See array definition in `Get user´s conversations` (API v4) ## Remove breakout rooms @@ -47,6 +49,8 @@ Group and public conversations can be used to host breakout rooms. + `200 OK` + `403 Forbidden` When the current user is not a moderator/owner + `404 Not Found` When the conversation could not be found for the participant + - Data: Parent conversation + See array definition in `Get user´s conversations` (API v4) ## Start breakout rooms @@ -60,6 +64,8 @@ Group and public conversations can be used to host breakout rooms. + `400 Bad Request` Error `mode`: When breakout rooms are not configured + `403 Forbidden` When the current user is not a moderator/owner + `404 Not Found` When the conversation could not be found for the participant + - Data: Array of conversations (breakout rooms and parent) + See array definition in `Get user´s conversations` (API v4) ## Stop breakout rooms @@ -73,6 +79,8 @@ Group and public conversations can be used to host breakout rooms. + `400 Bad Request` Error `mode`: When breakout rooms are not configured + `403 Forbidden` When the current user is not a moderator/owner + `404 Not Found` When the conversation could not be found for the participant + - Data: Array of conversations (breakout rooms and parent) + See array definition in `Get user´s conversations` (API v4) ## Broadcast message to breakout rooms @@ -93,6 +101,8 @@ Group and public conversations can be used to host breakout rooms. + `403 Forbidden` When the participant is not a moderator + `404 Not Found` When the conversation could not be found for the participant + `413 Payload Too Large` When the message was longer than the allowed limit of 32000 characters (check the `spreed => config => chat => max-length` capability for the limit) + - Data: Array of conversations (breakout rooms and parent) + See array definition in `Get user´s conversations` (API v4) ## Reorganize attendees @@ -113,6 +123,8 @@ Group and public conversations can be used to host breakout rooms. + `400 Bad Request` Error `attendeeMap`: When the attendee map contains an invalid room number or moderator + `403 Forbidden` When the current user is not a moderator/owner + `404 Not Found` When the conversation could not be found for the participant + - Data: Array of conversations (breakout rooms and parent) + See array definition in `Get user´s conversations` (API v4) ## Request assistance @@ -126,6 +138,8 @@ This endpoint allows participants to raise their hand (token is the breakout roo + `200 OK` + `400 Bad Request` Error `room`: When the room is not a breakout room or breakout rooms are not started + `404 Not Found` When the conversation could not be found for the participant + - Data: Breakout room + See array definition in `Get user´s conversations` (API v4) ## Reset request for assistance @@ -135,8 +149,10 @@ This endpoint allows participants to raise their hand (token is the breakout roo * Response: - Status code: + `200 OK` - + `400 Bad Request` Error `room`: When the room does not have breakout rooms configured + + `400 Bad Request` Error `room`: When the room is not a breakout room or breakout rooms are not started + `404 Not Found` When the conversation could not be found for the participant + - Data: Breakout room + See array definition in `Get user´s conversations` (API v4) ## List all breakout rooms @@ -164,3 +180,5 @@ This endpoint allows participants to raise their hand (token is the breakout roo + `400 Bad Request` Error `status`: When breakout rooms are not started + `400 Bad Request` Error `target`: When the target room is not breakout room of the parent + `404 Not Found` When the conversation could not be found for the participant + - Data: Target breakout room + See array definition in `Get user´s conversations` (API v4) 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; } } diff --git a/lib/Service/BreakoutRoomService.php b/lib/Service/BreakoutRoomService.php index caf3c8bcd..9872ecdd4 100644 --- a/lib/Service/BreakoutRoomService.php +++ b/lib/Service/BreakoutRoomService.php @@ -189,9 +189,10 @@ class BreakoutRoomService { /** * @param Room $parent * @param string $attendeeMap + * @return Room[] * @throws InvalidArgumentException When the map was invalid, breakout rooms are disabled or not configured for this conversation */ - public function applyAttendeeMap(Room $parent, string $attendeeMap): void { + public function applyAttendeeMap(Room $parent, string $attendeeMap): array { if (!$this->config->isBreakoutRoomsEnabled()) { throw new InvalidArgumentException('config'); } @@ -253,6 +254,8 @@ class BreakoutRoomService { } $this->addOthersToBreakoutRooms($breakoutRooms, $map); + + return $breakoutRooms; } /** @@ -342,7 +345,13 @@ class BreakoutRoomService { } } - public function broadcastChatMessage(Room $parent, Participant $participant, string $message): void { + /** + * @param Room $parent + * @param Participant $participant + * @param string $message + * @return Room[] + */ + public function broadcastChatMessage(Room $parent, Participant $participant, string $message): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { throw new \InvalidArgumentException('mode'); } @@ -356,13 +365,16 @@ class BreakoutRoomService { try { foreach ($breakoutRooms as $breakoutRoom) { $breakoutParticipant = $this->participantService->getParticipantByActor($breakoutRoom, $attendeeType, $attendeeId); - $this->chatManager->sendMessage($breakoutRoom, $breakoutParticipant, $attendeeType, $attendeeId, $message, $creationDateTime, null, '', false); + $comment = $this->chatManager->sendMessage($breakoutRoom, $breakoutParticipant, $attendeeType, $attendeeId, $message, $creationDateTime, null, '', false); + $breakoutRoom->setLastMessage($comment); } } finally { if ($shouldFlush) { $this->notificationManager->flush(); } } + + return $breakoutRooms; } public function requestAssistance(Room $breakoutRoom): void { @@ -392,7 +404,11 @@ class BreakoutRoomService { $this->roomService->setBreakoutRoomStatus($breakoutRoom, $status); } - public function startBreakoutRooms(Room $parent): void { + /** + * @param Room $parent + * @return Room[] + */ + public function startBreakoutRooms(Room $parent): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { throw new \InvalidArgumentException('mode'); } @@ -404,10 +420,14 @@ class BreakoutRoomService { $this->roomService->setBreakoutRoomStatus($parent, BreakoutRoom::STATUS_STARTED); - // FIXME missing to send the signaling messages so participants are moved + return $breakoutRooms; } - public function stopBreakoutRooms(Room $parent): void { + /** + * @param Room $parent + * @return Room[] + */ + public function stopBreakoutRooms(Room $parent): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { throw new \InvalidArgumentException('mode'); } @@ -423,10 +443,10 @@ class BreakoutRoomService { $this->roomService->setBreakoutRoomStatus($parent, BreakoutRoom::STATUS_STOPPED); - // FIXME missing to send the signaling messages so participants are moved back + return $breakoutRooms; } - public function switchBreakoutRoom(Room $parent, Participant $participant, string $targetToken): void { + public function switchBreakoutRoom(Room $parent, Participant $participant, string $targetToken): Room { if ($parent->getBreakoutRoomMode() !== BreakoutRoom::MODE_FREE) { throw new \InvalidArgumentException('mode'); } @@ -444,15 +464,15 @@ class BreakoutRoomService { $breakoutRooms = $this->manager->getMultipleRoomsByObject(BreakoutRoom::PARENT_OBJECT_TYPE, $parent->getToken()); - $foundTarget = false; + $target = null; foreach ($breakoutRooms as $breakoutRoom) { if ($targetToken === $breakoutRoom->getToken()) { - $foundTarget = true; + $target = $breakoutRoom; break; } } - if (!$foundTarget) { + if ($target === null) { throw new \InvalidArgumentException('target'); } @@ -489,6 +509,8 @@ class BreakoutRoomService { } } } + + return $target; } /** |