From 5da475f4c060e85266b5a113f50cc207e57a53c2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 Sep 2019 18:51:33 +0200 Subject: Populate the canStartCall value and add a capability Signed-off-by: Joas Schilling --- docs/capabilities.md | 1 + docs/conversation.md | 1 + lib/Capabilities.php | 1 + lib/Controller/RoomController.php | 15 +++++++++++++++ tests/php/CapabilitiesTest.php | 2 ++ 5 files changed, 20 insertions(+) diff --git a/docs/capabilities.md b/docs/capabilities.md index 7f3fa080e..4c253fcea 100644 --- a/docs/capabilities.md +++ b/docs/capabilities.md @@ -36,3 +36,4 @@ title: Capabilities ## 7.0 * `chat-read-marker` - The chat can be optionally marked read by clients manually, independent from the loading of the chat messages. * `webinary-lobby` - See [Webinary management](webinary.md) for technical details. +* `start-call-flag` - Only moderators or users might be able to start calls. diff --git a/docs/conversation.md b/docs/conversation.md index c9c18ab8b..cee3b2f46 100644 --- a/docs/conversation.md +++ b/docs/conversation.md @@ -59,6 +59,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1` `sessionId` | string | `'0'` if not connected, otherwise a 512 character long string `hasPassword` | bool | Flag if the conversation has a password `hasCall` | bool | Flag if the conversation has an active call + `canStartCall` | bool | Flag if the user can start a new call in this conversation (joining is always possible) (only available with `start-call-flag` capability) `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)) diff --git a/lib/Capabilities.php b/lib/Capabilities.php index dd1327d99..a2b96d10e 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -80,6 +80,7 @@ class Capabilities implements IPublicCapability { 'read-only-rooms', 'chat-read-marker', 'webinary-lobby', + 'start-call-flag', ], 'config' => [ 'chat' => [ diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 7a1af4a4e..a00c82483 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -42,6 +42,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\IComment; +use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use OCP\IUser; @@ -54,6 +55,8 @@ use Symfony\Component\EventDispatcher\GenericEvent; class RoomController extends AEnvironmentAwareController { /** @var string|null */ private $userId; + /** @var IConfig */ + private $config; /** @var TalkSession */ private $session; /** @var IUserManager */ @@ -78,6 +81,7 @@ class RoomController extends AEnvironmentAwareController { public function __construct(string $appName, ?string $UserId, IRequest $request, + IConfig $config, TalkSession $session, IUserManager $userManager, IGroupManager $groupManager, @@ -89,6 +93,7 @@ class RoomController extends AEnvironmentAwareController { ITimeFactory $timeFactory, IL10N $l10n) { parent::__construct($appName, $request); + $this->config = $config; $this->session = $session; $this->userId = $UserId; $this->userManager = $userManager; @@ -177,6 +182,7 @@ class RoomController extends AEnvironmentAwareController { 'count' => 0, 'hasPassword' => $room->hasPassword(), 'hasCall' => false, + 'canStartCall' => false, 'lastActivity' => 0, 'lastReadMessage' => 0, 'unreadMessages' => 0, @@ -244,6 +250,15 @@ class RoomController extends AEnvironmentAwareController { return $roomData; } + $defaultStartCall = (int) $this->config->getAppValue('spreed', 'start_calls', '0'); + if ($defaultStartCall === 0) { + $roomData['canStartCall'] = true; + } else if ($defaultStartCall === 1 && (!$currentParticipant->isGuest() || $currentParticipant->hasModeratorPermissions())) { + $roomData['canStartCall'] = true; + } else if ($defaultStartCall === 2 && $currentParticipant->hasModeratorPermissions()) { + $roomData['canStartCall'] = true; + } + $currentUser = $this->userManager->get($currentParticipant->getUser()); if ($currentUser instanceof IUser) { $lastReadMessage = $currentParticipant->getLastReadMessage(); diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index 8ddd71e09..c1eedac7d 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -91,6 +91,7 @@ class CapabilitiesTest extends TestCase { 'read-only-rooms', 'chat-read-marker', 'webinary-lobby', + 'start-call-flag', ], 'config' => [ 'chat' => [ @@ -146,6 +147,7 @@ class CapabilitiesTest extends TestCase { 'read-only-rooms', 'chat-read-marker', 'webinary-lobby', + 'start-call-flag', ], 'config' => [ 'chat' => [ -- cgit v1.2.3