Skip to content

Commit

Permalink
fix(api): Properly typed breakoutRoom update
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Sep 11, 2024
1 parent e66a554 commit 97ff05c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
29 changes: 29 additions & 0 deletions lib/Exceptions/RoomProperty/BreakoutRoomModeException.php
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions lib/Exceptions/RoomProperty/BreakoutRoomStatusException.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 4 additions & 1 deletion lib/Service/BreakoutRoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -115,7 +116,9 @@ public function setupBreakoutRooms(Room $parent, int $mode, int $amount, string
throw new InvalidArgumentException('room');
}

if (!$this->roomService->setBreakoutRoomMode($parent, $mode)) {
try {
$this->roomService->setBreakoutRoomMode($parent, $mode);
} catch (BreakoutRoomModeException) {
throw new InvalidArgumentException('mode');
}

Expand Down
22 changes: 14 additions & 8 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;
Expand Down Expand Up @@ -805,14 +807,18 @@ public function setMessageExpiration(Room $room, int $seconds): void {
$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();
Expand All @@ -829,18 +835,20 @@ public function setBreakoutRoomMode(Room $room, int $mode): bool {

$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();
Expand All @@ -858,8 +866,6 @@ public function setBreakoutRoomStatus(Room $room, int $status): bool {
$oldStatus = $room->getBreakoutRoomStatus();
$event = new RoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_BREAKOUT_ROOM_STATUS, $status, $oldStatus);
$this->dispatcher->dispatchTyped($event);

return true;
}

/**
Expand Down

0 comments on commit 97ff05c

Please sign in to comment.