From c960e4e25c16b0d2d54c0396ab4f11e19192414c Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Wed, 26 Apr 2017 11:59:52 +0200 Subject: [PATCH 1/3] Add video call action to internal users in contacts menu. Signed-off-by: Ivan Sein --- appinfo/info.xml | 3 + lib/ContactsMenu/Providers/CallProvider.php | 74 +++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 lib/ContactsMenu/Providers/CallProvider.php diff --git a/appinfo/info.xml b/appinfo/info.xml index da6f9a597ea..655e9395ae0 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -74,4 +74,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m OCA\Spreed\Migration\FillRoomTokens + + OCA\Spreed\ContactsMenu\Providers\CallProvider + diff --git a/lib/ContactsMenu/Providers/CallProvider.php b/lib/ContactsMenu/Providers/CallProvider.php new file mode 100644 index 00000000000..a879127ce4a --- /dev/null +++ b/lib/ContactsMenu/Providers/CallProvider.php @@ -0,0 +1,74 @@ + + * + * @author 2017 Ivan Sein + * + * @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 . + * + */ + +namespace OCA\Spreed\ContactsMenu\Providers; + +use OCP\Contacts\ContactsMenu\IActionFactory; +use OCP\Contacts\ContactsMenu\IEntry; +use OCP\Contacts\ContactsMenu\IProvider; +use OCP\IL10N; +use OCP\IURLGenerator; + +/** + * @todo move to contacts app + */ +class CallProvider implements IProvider { + + /** @var IActionFactory */ + private $actionFactory; + + /** @var IURLGenerator */ + private $urlGenerator; + + /** @var IL10N */ + private $l10n; + + /** + * @param IActionFactory $actionFactory + * @param IURLGenerator $urlGenerator + */ + public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator, IL10N $l10n) { + $this->actionFactory = $actionFactory; + $this->urlGenerator = $urlGenerator; + $this->l10n = $l10n; + } + + /** + * @param IEntry $entry + */ + public function process(IEntry $entry) { + $uid = $entry->getProperty('UID'); + + if (is_null($uid)) { + // Nothing to do + return; + } + + $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/video.svg')); + $callUrl = $this->urlGenerator->getAbsoluteURL('/index.php/apps/spreed/'); + $action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Video Call'), $callUrl); + $entry->addAction($action); + } + +} From 822ff12de632e5683e3a92ea4baf4b4d353ead41 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Wed, 26 Apr 2017 12:12:44 +0200 Subject: [PATCH 2/3] Ignore not internal users. Signed-off-by: Ivan Sein --- lib/ContactsMenu/Providers/CallProvider.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ContactsMenu/Providers/CallProvider.php b/lib/ContactsMenu/Providers/CallProvider.php index a879127ce4a..353c7e994c9 100644 --- a/lib/ContactsMenu/Providers/CallProvider.php +++ b/lib/ContactsMenu/Providers/CallProvider.php @@ -65,6 +65,11 @@ public function process(IEntry $entry) { return; } + if ($entry->getProperty('isLocalSystemBook') === true) { + // Not internal user + return; + } + $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/video.svg')); $callUrl = $this->urlGenerator->getAbsoluteURL('/index.php/apps/spreed/'); $action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Video Call'), $callUrl); From ea2d2a4fad2a14958334a70c60bd1e3a7fd4b94b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 26 Apr 2017 12:27:50 +0200 Subject: [PATCH 3/3] Open one2one call when the user follows the link Signed-off-by: Joas Schilling --- lib/ContactsMenu/Providers/CallProvider.php | 4 ++-- lib/Controller/PageController.php | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ContactsMenu/Providers/CallProvider.php b/lib/ContactsMenu/Providers/CallProvider.php index 353c7e994c9..df889e1f48d 100644 --- a/lib/ContactsMenu/Providers/CallProvider.php +++ b/lib/ContactsMenu/Providers/CallProvider.php @@ -65,13 +65,13 @@ public function process(IEntry $entry) { return; } - if ($entry->getProperty('isLocalSystemBook') === true) { + if ($entry->getProperty('isLocalSystemBook') !== true) { // Not internal user return; } $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/video.svg')); - $callUrl = $this->urlGenerator->getAbsoluteURL('/index.php/apps/spreed/'); + $callUrl = $this->urlGenerator->linkToRouteAbsolute('spreed.page.index') . '?callUser=' . $uid; $action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Video Call'), $callUrl); $entry->addAction($action); } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 614ea019236..39541e4adfd 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -28,6 +28,7 @@ use OCA\Spreed\Manager; use OCA\Spreed\Room; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -41,6 +42,8 @@ class PageController extends Controller { /** @var string */ private $userId; + /** @var ApiController */ + private $api; /** @var IL10N */ private $l10n; /** @var ILogger */ @@ -57,6 +60,7 @@ class PageController extends Controller { /** * @param string $appName * @param IRequest $request + * @param ApiController $api * @param string $UserId * @param IL10N $l10n * @param ILogger $logger @@ -67,6 +71,7 @@ class PageController extends Controller { */ public function __construct($appName, IRequest $request, + ApiController $api, $UserId, IL10N $l10n, ILogger $logger, @@ -76,6 +81,7 @@ public function __construct($appName, IManager $notificationManager) { parent::__construct($appName, $request); $this->userId = $UserId; + $this->api = $api; $this->l10n = $l10n; $this->logger = $logger; $this->manager = $manager; @@ -89,10 +95,11 @@ public function __construct($appName, * @NoCSRFRequired * * @param string $token + * @param string $callUser * @return TemplateResponse - * @throws HintException + * @throws HintException|RedirectResponse */ - public function index($token = '') { + public function index($token = '', $callUser = '') { if ($this->userId === null) { return $this->guestEnterRoom($token); } @@ -121,6 +128,12 @@ public function index($token = '') { // Room not found, redirect to main page $token = ''; } + } else { + $response = $this->api->createOneToOneRoom($callUser); + if ($response->getStatus() !== Http::STATUS_NOT_FOUND) { + $data = $response->getData(); + return new RedirectResponse($this->url->linkToRoute('spreed.page.index', ['token' => $data['token']])); + } } $params = [