mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
fix(api): Properly typed breakoutRoom update
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
428aa9164a
commit
38a244b86b
4 changed files with 76 additions and 9 deletions
29
lib/Exceptions/RoomProperty/BreakoutRoomModeException.php
Normal file
29
lib/Exceptions/RoomProperty/BreakoutRoomModeException.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Exceptions\RoomProperty;
|
||||
|
||||
class BreakoutRoomModeException extends \InvalidArgumentException {
|
||||
public const REASON_VALUE = 'value';
|
||||
|
||||
/**
|
||||
* @param self::REASON_* $reason
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $reason,
|
||||
) {
|
||||
parent::__construct($reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self::REASON_*
|
||||
*/
|
||||
public function getReason(): string {
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
29
lib/Exceptions/RoomProperty/BreakoutRoomStatusException.php
Normal file
29
lib/Exceptions/RoomProperty/BreakoutRoomStatusException.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Exceptions\RoomProperty;
|
||||
|
||||
class BreakoutRoomStatusException extends \InvalidArgumentException {
|
||||
public const REASON_VALUE = 'value';
|
||||
|
||||
/**
|
||||
* @param self::REASON_* $reason
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $reason,
|
||||
) {
|
||||
parent::__construct($reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self::REASON_*
|
||||
*/
|
||||
public function getReason(): string {
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ use OCA\Talk\Chat\ChatManager;
|
|||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Events\AAttendeeRemovedEvent;
|
||||
use OCA\Talk\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\BreakoutRoomModeException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Model\BreakoutRoom;
|
||||
|
|
@ -115,7 +116,9 @@ class BreakoutRoomService {
|
|||
throw new InvalidArgumentException('room');
|
||||
}
|
||||
|
||||
if (!$this->roomService->setBreakoutRoomMode($parent, $mode)) {
|
||||
try {
|
||||
$this->roomService->setBreakoutRoomMode($parent, $mode);
|
||||
} catch (BreakoutRoomModeException) {
|
||||
throw new InvalidArgumentException('mode');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ use OCA\Talk\Events\RoomModifiedEvent;
|
|||
use OCA\Talk\Events\RoomPasswordVerifyEvent;
|
||||
use OCA\Talk\Events\RoomSyncedEvent;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\BreakoutRoomModeException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\BreakoutRoomStatusException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\CallRecordingException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\DefaultPermissionsException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\DescriptionException;
|
||||
|
|
@ -805,14 +807,18 @@ class RoomService {
|
|||
$this->dispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
public function setBreakoutRoomMode(Room $room, int $mode): bool {
|
||||
/**
|
||||
* @psalm-param BreakoutRoom::MODE_* $mode
|
||||
* @throws BreakoutRoomModeException
|
||||
*/
|
||||
public function setBreakoutRoomMode(Room $room, int $mode): void {
|
||||
if (!in_array($mode, [
|
||||
BreakoutRoom::MODE_NOT_CONFIGURED,
|
||||
BreakoutRoom::MODE_AUTOMATIC,
|
||||
BreakoutRoom::MODE_MANUAL,
|
||||
BreakoutRoom::MODE_FREE
|
||||
], true)) {
|
||||
return false;
|
||||
throw new BreakoutRoomModeException(BreakoutRoomModeException::REASON_VALUE);
|
||||
}
|
||||
|
||||
$oldMode = $room->getBreakoutRoomMode();
|
||||
|
|
@ -829,18 +835,20 @@ class RoomService {
|
|||
|
||||
$event = new RoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_BREAKOUT_ROOM_MODE, $mode, $oldMode);
|
||||
$this->dispatcher->dispatchTyped($event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setBreakoutRoomStatus(Room $room, int $status): bool {
|
||||
/**
|
||||
* @psalm-param BreakoutRoom::STATUS_* $status
|
||||
* @throws BreakoutRoomStatusException
|
||||
*/
|
||||
public function setBreakoutRoomStatus(Room $room, int $status): void {
|
||||
if (!in_array($status, [
|
||||
BreakoutRoom::STATUS_STOPPED,
|
||||
BreakoutRoom::STATUS_STARTED,
|
||||
BreakoutRoom::STATUS_ASSISTANCE_RESET,
|
||||
BreakoutRoom::STATUS_ASSISTANCE_REQUESTED,
|
||||
], true)) {
|
||||
return false;
|
||||
throw new BreakoutRoomStatusException(BreakoutRoomStatusException::REASON_VALUE);
|
||||
}
|
||||
|
||||
$oldStatus = $room->getBreakoutRoomStatus();
|
||||
|
|
@ -858,8 +866,6 @@ class RoomService {
|
|||
$oldStatus = $room->getBreakoutRoomStatus();
|
||||
$event = new RoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_BREAKOUT_ROOM_STATUS, $status, $oldStatus);
|
||||
$this->dispatcher->dispatchTyped($event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue