Browse Source

Allow a timer as well

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/1926/head
Joas Schilling 6 years ago
committed by Daniel Calviño Sánchez
parent
commit
8cd50644d4
  1. 2
      appinfo/routes.php
  2. 2
      docs/conversation.md
  3. 1
      docs/webinary.md
  4. 10
      lib/Controller/RoomController.php
  5. 18
      lib/Controller/WebinaryController.php
  6. 6
      lib/Manager.php
  7. 3
      lib/Migration/Version6099Date20190627172429.php
  8. 22
      lib/Room.php
  9. 2
      tests/php/Signaling/BackendNotifierTest.php

2
appinfo/routes.php

@ -397,7 +397,7 @@ return [
* Webinary
*/
[
'name' => 'Webinary#setLobbyState',
'name' => 'Webinary#setLobby',
'url' => '/api/{apiVersion}/room/{token}/webinary/lobby',
'verb' => 'PUT',
'requirements' => [

2
docs/conversation.md

@ -62,6 +62,8 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
`lastActivity` | int | Timestamp of the last activity in the conversation, in seconds and UTC time zone
`isFavorite` | bool | Flag if the conversation is favorited by the user
`notificationLevel` | int | The notification level for the user (one of `Participant::NOTIFY_*` (1-3))
`lobbyState` | int | Webinary lobby restriction (0-1), if the participant is a moderator they can always join the conversation (only available with `webinary-lobby` capability)
`lobbyTimer` | string | Datetime when the lobby will be automatically disabled ([Format: `Y-m-d\TH:i:sP`](https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.atom)) (only available with `webinary-lobby` capability)
`unreadMessages` | int | Number of unread chat messages in the conversation (only available with `chat-v2` capability)
`unreadMention` | bool | Flag if the user was mentioned since their last visit
`lastReadMessage` | int | ID of the last read message in a room (only available with `chat-read-marker` capability)

1
docs/webinary.md

@ -12,6 +12,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
field | type | Description
------|------|------------
`state` | int | New state for the conversation
`timer` | string | Datetime when the lobby state is reset to all participants ([Format: `Y-m-d\TH:i:sP`](https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.atom))
* Response:
- Header:

10
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(),
]);

18
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);
}

6
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']
);

3
lib/Migration/Version6099Date20190627172429.php

@ -50,6 +50,9 @@ class Version6099Date20190627172429 extends SimpleMigrationStep {
'length' => 6,
'default' => 0,
]);
$table->addColumn('lobby_timer', Type::DATETIME, [
'notnull' => false,
]);
}
}

22
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;

2
tests/php/Signaling/BackendNotifierTest.php

@ -323,7 +323,7 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomLobbyStateChanged() {
$room = $this->manager->createPublicRoom();
$room->setLobbyState(Webinary::MODERATORS_ONLY);
$room->setLobby(Webinary::MODERATORS_ONLY, null);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {

Loading…
Cancel
Save