diff options
author | Joas Schilling <coding@schilljs.com> | 2019-06-27 21:18:57 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2019-08-28 11:26:03 +0300 |
commit | a48650c908e0737007a21a5f08a9ddc6f707c2da (patch) | |
tree | a568242461083c2caedc26bedba829e394aad7d5 /lib | |
parent | 12952b93c93ba5eb2974b400676783bd96443345 (diff) |
Read and allow to set the lobby state
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Manager.php | 1 | ||||
-rw-r--r-- | lib/Room.php | 51 | ||||
-rw-r--r-- | lib/Webinary.php | 31 |
3 files changed, 83 insertions, 0 deletions
diff --git a/lib/Manager.php b/lib/Manager.php index 8933f3170..66e664261 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -140,6 +140,7 @@ class Manager { (int) $row['id'], (int) $row['type'], (int) $row['read_only'], + (int) $row['lobby_state'], $row['token'], $row['name'], $row['password'], diff --git a/lib/Room.php b/lib/Room.php index 3e6f1ab24..20125ee03 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -71,6 +71,8 @@ class Room { private $type; /** @var int */ private $readOnly; + /** @var int */ + private $lobbyState; /** @var string */ private $token; /** @var string */ @@ -104,6 +106,7 @@ class Room { int $id, int $type, int $readOnly, + int $lobbyState, string $token, string $name, string $password, @@ -122,6 +125,7 @@ class Room { $this->id = $id; $this->type = $type; $this->readOnly = $readOnly; + $this->lobbyState = $lobbyState; $this->token = $token; $this->name = $name; $this->password = $password; @@ -145,6 +149,10 @@ class Room { return $this->readOnly; } + public function getLobbyState(): int { + return $this->lobbyState; + } + public function getToken(): string { return $this->token; } @@ -497,6 +505,49 @@ class Room { return true; } + /** + * @param int $newState Currently it is only allowed to change between + * `Webinary::MODERATORS_ONLY` and `Webinary::ALL_PARTICIPANTS` + * Also it's not allowed in one-to-one conversations, + * file conversations and password request conversations. + * @return bool True when the change was valid, false otherwise + */ + public function setLobbyState(int $newState): bool { + $oldState = $this->getLobbyState(); + + if (!in_array($this->getType(), [self::GROUP_CALL, self::PUBLIC_CALL], true)) { + return false; + } + + if ($this->getObjectType() !== '') { + return false; + } + + if (!in_array($newState, [Webinary::MODERATORS_ONLY, Webinary::ALL_PARTICIPANTS], true)) { + return false; + } + + $this->dispatcher->dispatch(self::class . '::preSetLobbyState', new GenericEvent($this, [ + 'newState' => $newState, + 'oldState' => $oldState, + ])); + + $query = $this->db->getQueryBuilder(); + $query->update('talk_rooms') + ->set('lobby_state', $query->createNamedParameter($newState, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); + $query->execute(); + + $this->lobbyState = $newState; + + $this->dispatcher->dispatch(self::class . '::postSetLobbyState', new GenericEvent($this, [ + 'newState' => $newState, + 'oldState' => $oldState, + ])); + + return true; + } + public function ensureOneToOneRoomIsFilled(): void { if ($this->getType() !== self::ONE_TO_ONE_CALL) { return; diff --git a/lib/Webinary.php b/lib/Webinary.php new file mode 100644 index 000000000..f6bb76481 --- /dev/null +++ b/lib/Webinary.php @@ -0,0 +1,31 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Spreed; + + +class Webinary { + + public const ALL_PARTICIPANTS = 0; + public const MODERATORS_ONLY = 1; + +} |