Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contacts menu integration #300

Merged
merged 3 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<step>OCA\Spreed\Migration\FillRoomTokens</step>
</post-migration>
</repair-steps>
<contactsmenu>
<provider>OCA\Spreed\ContactsMenu\Providers\CallProvider</provider>
</contactsmenu>
</info>
79 changes: 79 additions & 0 deletions lib/ContactsMenu/Providers/CallProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* @copyright 2017 Ivan Sein <ivan@nextcloud.com>
*
* @author 2017 Ivan Sein <ivan@nextcloud.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\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;
}

if ($entry->getProperty('isLocalSystemBook') !== true) {
// Not internal user
return;
}

$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/video.svg'));
$callUrl = $this->urlGenerator->linkToRouteAbsolute('spreed.page.index') . '?callUser=' . $uid;
$action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Video Call'), $callUrl);
$entry->addAction($action);
}

}
17 changes: 15 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +42,8 @@
class PageController extends Controller {
/** @var string */
private $userId;
/** @var ApiController */
private $api;
/** @var IL10N */
private $l10n;
/** @var ILogger */
Expand All @@ -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
Expand All @@ -67,6 +71,7 @@ class PageController extends Controller {
*/
public function __construct($appName,
IRequest $request,
ApiController $api,
$UserId,
IL10N $l10n,
ILogger $logger,
Expand All @@ -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;
Expand All @@ -89,10 +95,11 @@ public function __construct($appName,
* @NoCSRFRequired
*
* @param string $token
* @param string $callUser
* @return TemplateResponse
* @throws HintException
* @throws HintException|RedirectResponse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it returns the response 😉

*/
public function index($token = '') {
public function index($token = '', $callUser = '') {
if ($this->userId === null) {
return $this->guestEnterRoom($token);
}
Expand Down Expand Up @@ -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 = [
Expand Down