Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-07-04 16:33:16 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2019-08-28 11:28:06 +0300
commit8cd50644d406364a43acfebed30836694c632199 (patch)
tree215876ba9bdf847621b37c43b9aeb22829d4c95d /lib
parent36e3da092c496d7fbde7fa31c81064605bb99ca8 (diff)
Allow a timer as well
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/RoomController.php10
-rw-r--r--lib/Controller/WebinaryController.php18
-rw-r--r--lib/Manager.php6
-rw-r--r--lib/Migration/Version6099Date20190627172429.php3
-rw-r--r--lib/Room.php22
5 files changed, 55 insertions, 4 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 549bd4cf7..bb0de64e8 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -37,6 +37,7 @@ use OCA\Spreed\Manager;
use OCA\Spreed\Participant;
use OCA\Spreed\Room;
use OCA\Spreed\TalkSession;
+use OCA\Spreed\Webinary;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -201,6 +202,13 @@ class RoomController extends AEnvironmentAwareController {
$lastActivity = 0;
}
+ $lobbyTimer = $room->getLobbyTimer();
+ if ($lobbyTimer instanceof \DateTimeInterface) {
+ $lobbyTimer = $lobbyTimer->format(\DateTime::ATOM);
+ } else {
+ $lobbyTimer = '';
+ }
+
$roomData = array_merge($roomData, [
'name' => $room->getName(),
'displayName' => $room->getDisplayName($currentParticipant->getUser()),
@@ -216,6 +224,8 @@ class RoomController extends AEnvironmentAwareController {
'lastActivity' => $lastActivity,
'isFavorite' => $currentParticipant->isFavorite(),
'notificationLevel' => $currentParticipant->getNotificationLevel(),
+ 'lobbyState' => $room->getLobbyState(),
+ 'lobbyTimer' => $lobbyTimer,
'lastPing' => $currentParticipant->getLastPing(),
'sessionId' => $currentParticipant->getSessionId(),
]);
diff --git a/lib/Controller/WebinaryController.php b/lib/Controller/WebinaryController.php
index d67cd2843..e34a1f612 100644
--- a/lib/Controller/WebinaryController.php
+++ b/lib/Controller/WebinaryController.php
@@ -26,13 +26,19 @@ namespace OCA\Spreed\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
class WebinaryController extends AEnvironmentAwareController {
+ /** @var ITimeFactory */
+ protected $timeFactory;
+
public function __construct(string $appName,
- IRequest $request) {
+ IRequest $request,
+ ITimeFactory $timeFactory) {
parent::__construct($appName, $request);
+ $this->timeFactory = $timeFactory;
}
/**
@@ -40,10 +46,16 @@ class WebinaryController extends AEnvironmentAwareController {
* @RequireModeratorParticipant
*
* @param int $state
+ * @param string $timer
* @return DataResponse
*/
- public function setLobbyState(int $state): DataResponse {
- if (!$this->room->setLobbyState($state)) {
+ public function setLobby(int $state, ?string $timer = null): DataResponse {
+ $timerDateTime = null;
+ if (trim((string) $timer) !== '') {
+ $timerDateTime = $this->timeFactory->getDateTime($timer);
+ }
+
+ if (!$this->room->setLobby($state, $timerDateTime)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
diff --git a/lib/Manager.php b/lib/Manager.php
index 66e664261..44b3e5061 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -117,6 +117,11 @@ class Manager {
$lastActivity = $this->timeFactory->getDateTime($row['last_activity']);
}
+ $lobbyTimer = null;
+ if (!empty($row['lobby_timer'])) {
+ $lobbyTimer = $this->timeFactory->getDateTime($row['lobby_timer']);
+ }
+
$lastMessage = null;
if (!empty($row['comment_id'])) {
$lastMessage = $this->commentsManager->getCommentFromData(array_merge($row, [
@@ -148,6 +153,7 @@ class Manager {
$activeSince,
$lastActivity,
$lastMessage,
+ $lobbyTimer,
(string) $row['object_type'],
(string) $row['object_id']
);
diff --git a/lib/Migration/Version6099Date20190627172429.php b/lib/Migration/Version6099Date20190627172429.php
index 5c50244cc..6e8328d43 100644
--- a/lib/Migration/Version6099Date20190627172429.php
+++ b/lib/Migration/Version6099Date20190627172429.php
@@ -50,6 +50,9 @@ class Version6099Date20190627172429 extends SimpleMigrationStep {
'length' => 6,
'default' => 0,
]);
+ $table->addColumn('lobby_timer', Type::DATETIME, [
+ 'notnull' => false,
+ ]);
}
}
diff --git a/lib/Room.php b/lib/Room.php
index 20125ee03..79c9b2bb5 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -73,6 +73,8 @@ class Room {
private $readOnly;
/** @var int */
private $lobbyState;
+ /** @var \DateTime|null */
+ private $lobbyTimer;
/** @var string */
private $token;
/** @var string */
@@ -114,6 +116,7 @@ class Room {
\DateTime $activeSince = null,
\DateTime $lastActivity = null,
IComment $lastMessage = null,
+ \DateTime $lobbyTimer = null,
string $objectType = '',
string $objectId = '') {
$this->manager = $manager;
@@ -133,6 +136,7 @@ class Room {
$this->activeSince = $activeSince;
$this->lastActivity = $lastActivity;
$this->lastMessage = $lastMessage;
+ $this->lobbyTimer = $lobbyTimer;
$this->objectType = $objectType;
$this->objectId = $objectId;
}
@@ -150,9 +154,21 @@ class Room {
}
public function getLobbyState(): int {
+ $this->validateTimer();
return $this->lobbyState;
}
+ public function getLobbyTimer(): ?\DateTime {
+ $this->validateTimer();
+ return $this->lobbyTimer;
+ }
+
+ protected function validateTimer(): void {
+ if ($this->lobbyTimer !== null && $this->lobbyTimer < $this->timeFactory->getDateTime()) {
+ $this->setLobby(Webinary::ALL_PARTICIPANTS, null);
+ }
+ }
+
public function getToken(): string {
return $this->token;
}
@@ -510,9 +526,10 @@ class Room {
* `Webinary::MODERATORS_ONLY` and `Webinary::ALL_PARTICIPANTS`
* Also it's not allowed in one-to-one conversations,
* file conversations and password request conversations.
+ * @param \DateTime|null $dateTime
* @return bool True when the change was valid, false otherwise
*/
- public function setLobbyState(int $newState): bool {
+ public function setLobby(int $newState, ?\DateTime $dateTime): bool {
$oldState = $this->getLobbyState();
if (!in_array($this->getType(), [self::GROUP_CALL, self::PUBLIC_CALL], true)) {
@@ -530,11 +547,13 @@ class Room {
$this->dispatcher->dispatch(self::class . '::preSetLobbyState', new GenericEvent($this, [
'newState' => $newState,
'oldState' => $oldState,
+ 'lobbyTimer' => $dateTime,
]));
$query = $this->db->getQueryBuilder();
$query->update('talk_rooms')
->set('lobby_state', $query->createNamedParameter($newState, IQueryBuilder::PARAM_INT))
+ ->set('lobby_timer', $query->createNamedParameter($dateTime, IQueryBuilder::PARAM_DATE))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@@ -543,6 +562,7 @@ class Room {
$this->dispatcher->dispatch(self::class . '::postSetLobbyState', new GenericEvent($this, [
'newState' => $newState,
'oldState' => $oldState,
+ 'lobbyTimer' => $dateTime,
]));
return true;