diff --git a/appinfo/routes.php b/appinfo/routes.php index 566473307..d0fc5168f 100755 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -38,16 +38,21 @@ return [ 'url' => '/messages', 'verb' => 'GET', ], - [ - 'name' => 'api#createRoom', - 'url' => '/api/room', - 'verb' => 'POST', - ], [ 'name' => 'api#getRooms', 'url' => '/api/room', 'verb' => 'GET', ], + [ + 'name' => 'api#makePublic', + 'url' => '/api/room/public', + 'verb' => 'POST', + ], + [ + 'name' => 'api#makePrivate', + 'url' => '/api/room/public', + 'verb' => 'DELETE', + ], [ 'name' => 'api#addParticipantToRoom', 'url' => '/api/room/{roomId}', diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index b4207e51d..c48543d74 100755 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -336,6 +336,46 @@ class ApiController extends Controller { return new JSONResponse([]); } + /** + * @NoAdminRequired + * + * @param int $roomId + * @return JSONResponse + */ + public function makePublic($roomId) { + try { + $room = $this->manager->getRoomForParticipant($roomId, $this->userId); + } catch (RoomNotFoundException $e) { + return new JSONResponse([], Http::STATUS_NOT_FOUND); + } + + if ($room->getType() !== Room::PUBLIC_CALL) { + $room->changeType(Room::PUBLIC_CALL); + } + + return new JSONResponse(); + } + + /** + * @NoAdminRequired + * + * @param int $roomId + * @return JSONResponse + */ + public function makePrivate($roomId) { + try { + $room = $this->manager->getRoomForParticipant($roomId, $this->userId); + } catch (RoomNotFoundException $e) { + return new JSONResponse([], Http::STATUS_NOT_FOUND); + } + + if ($room->getType() === Room::PUBLIC_CALL) { + $room->changeType(Room::GROUP_CALL); + } + + return new JSONResponse(); + } + /** * @NoAdminRequired * diff --git a/lib/Room.php b/lib/Room.php index be931c275..3adb2eed5 100755 --- a/lib/Room.php +++ b/lib/Room.php @@ -32,6 +32,7 @@ use OCP\IUser; class Room { const ONE_TO_ONE_CALL = 1; const GROUP_CALL = 2; + const PUBLIC_CALL = 3; /** @var IDBConnection */ private $db; @@ -94,7 +95,7 @@ class Room { } /** - * @param int $newType Currently it is only allowed to change to: Room::GROUP_CALL + * @param int $newType Currently it is only allowed to change to: Room::GROUP_CALL, Room::PUBLIC_CALL * @return bool True when the change was valid, false otherwise */ public function changeType($newType) { @@ -102,7 +103,7 @@ class Room { return true; } - if (!in_array($newType, [Room::GROUP_CALL])) { + if (!in_array($newType, [Room::GROUP_CALL, Room::PUBLIC_CALL])) { return false; }