Skip to content
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
32 changes: 6 additions & 26 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\TalkSession;
use OCA\Talk\TInitialState;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand All @@ -48,9 +49,11 @@
use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\Util;

class PageController extends Controller {

use TInitialState;

/** @var string|null */
private $userId;
/** @var RoomController */
Expand All @@ -69,12 +72,6 @@ class PageController extends Controller {
private $notificationManager;
/** @var IAppManager */
private $appManager;
/** @var IInitialStateService */
private $initialStateService;
/** @var Config */
private $talkConfig;
/** @var IConfig */
private $serverConfig;

public function __construct(string $appName,
IRequest $request,
Expand Down Expand Up @@ -222,18 +219,7 @@ public function index(string $token = '', string $callUser = '', string $passwor
}
}

// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => "app", 'class' => 'nc-enable-screensharing-extension']);

$this->initialStateService->provideInitialState(
'talk', 'prefer_h264',
$this->serverConfig->getAppValue('spreed', 'prefer_h264', 'no') === 'yes'
);

$this->initialStateService->provideInitialState(
'talk', 'circles_enabled',
$this->appManager->isEnabledForUser('circles', $user)
);
$this->publishInitialStateForUser($user, $this->appManager);

$response = new TemplateResponse($this->appName, 'index');
$csp = new ContentSecurityPolicy();
Expand Down Expand Up @@ -283,13 +269,7 @@ protected function guestEnterRoom(string $token, string $password): Response {
}
}

// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => "app", 'class' => 'nc-enable-screensharing-extension']);

$this->initialStateService->provideInitialState(
'talk', 'prefer_h264',
$this->serverConfig->getAppValue('spreed', 'prefer_h264', 'no') === 'yes'
);
$this->publishInitialStateForGuest();

$response = new PublicTemplateResponse($this->appName, 'index');
$response->setFooterVisible(false);
Expand Down
42 changes: 37 additions & 5 deletions lib/Files/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,74 @@

use OCA\Files\Event\LoadSidebar;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Config;
use OCA\Talk\TInitialState;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Util;

/**
* Helper class to add the Talk UI to the sidebar of the Files app.
*/
class TemplateLoader implements IEventListener {

use TInitialState;

/** @var IAppManager */
private $appManager;
/** @var IUserSession */
private $userSession;

public function __construct(IInitialStateService $initialStateService,
Config $talkConfig,
IConfig $serverConfig,
IAppManager $appManager,
IUserSession $userSession) {
$this->initialStateService = $initialStateService;
$this->talkConfig = $talkConfig;
$this->serverConfig = $serverConfig;
$this->appManager = $appManager;
$this->userSession = $userSession;
}


public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addServiceListener(LoadSidebar::class, TemplateLoader::class);
$dispatcher->addServiceListener(LoadSidebar::class, self::class);
}

/**
* Loads the Talk UI in the sidebar of the Files app.
*
* This method should be called when handling the LoadSidebar event of the
* Files app.
*
* @param Event $event
*/
public function handle(Event $event): void {
if (!($event instanceof LoadSidebar)) {
return;
}

$config = \OC::$server->getConfig();
if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1') {
if ($this->serverConfig->getAppValue('spreed', 'conversations_files', '1') !== '1') {
return;
}

Util::addStyle(Application::APP_ID, 'merged-files');
Util::addScript(Application::APP_ID, 'talk-files-sidebar');
Util::addScript(Application::APP_ID, 'talk-files-sidebar-loader');

// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => "app", 'class' => 'nc-enable-screensharing-extension']);
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
$this->publishInitialStateForUser($user, $this->appManager);
} else {
$this->publishInitialStateForGuest();
}
}

}
28 changes: 21 additions & 7 deletions lib/PublicShare/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@

namespace OCA\Talk\PublicShare;

use OCA\Talk\Config;
use OCA\Talk\TInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\FileInfo;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand All @@ -39,11 +43,23 @@
*/
class TemplateLoader {

use TInitialState;

public function __construct(IInitialStateService $initialStateService,
Config $talkConfig,
IConfig $serverConfig) {
$this->initialStateService = $initialStateService;
$this->talkConfig = $talkConfig;
$this->serverConfig = $serverConfig;
}

public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', static function(GenericEvent $event) {
/** @var IShare $share */
$share = $event->getArgument('share');
self::loadTalkSidebarUi($share);
/** @var self $templateLoader */
$templateLoader = \OC::$server->query(self::class);
$templateLoader->loadTalkSidebarUi($share);
});
}

Expand All @@ -55,10 +71,9 @@ public static function register(IEventDispatcher $dispatcher): void {
*
* @param IShare $share
*/
public static function loadTalkSidebarUi(IShare $share): void {
$config = \OC::$server->getConfig();
if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1' ||
$config->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') {
public function loadTalkSidebarUi(IShare $share): void {
if ($this->serverConfig->getAppValue('spreed', 'conversations_files', '1') !== '1' ||
$this->serverConfig->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') {
return;
}

Expand All @@ -69,8 +84,7 @@ public static function loadTalkSidebarUi(IShare $share): void {
Util::addStyle('spreed', 'merged-public-share');
Util::addScript('spreed', 'talk-public-share-sidebar');

// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => "app", 'class' => 'nc-enable-screensharing-extension']);
$this->publishInitialStateForGuest();
}

}
26 changes: 21 additions & 5 deletions lib/PublicShareAuth/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

namespace OCA\Talk\PublicShareAuth;

use OCA\Talk\Config;
use OCA\Talk\TInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand All @@ -37,11 +41,23 @@
*/
class TemplateLoader {

use TInitialState;

public function __construct(IInitialStateService $initialStateService,
Config $talkConfig,
IConfig $serverConfig) {
$this->initialStateService = $initialStateService;
$this->talkConfig = $talkConfig;
$this->serverConfig = $serverConfig;
}

public static function register(IEventDispatcher $dispatcher): void {
$listener = function(GenericEvent $event) {
$listener = static function(GenericEvent $event) {
/** @var IShare $share */
$share = $event->getArgument('share');
self::loadRequestPasswordByTalkUi($share);
/** @var self $templateLoader */
$templateLoader = \OC::$server->query(self::class);
$templateLoader->loadRequestPasswordByTalkUi($share);
};
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $listener);
}
Expand All @@ -58,16 +74,16 @@ public static function register(IEventDispatcher $dispatcher): void {
*
* @param IShare $share
*/
public static function loadRequestPasswordByTalkUi(IShare $share): void {
public function loadRequestPasswordByTalkUi(IShare $share): void {
if (!$share->getSendPasswordByTalk()) {
return;
}

Util::addStyle('spreed', 'merged-share-auth');
Util::addScript('spreed', 'talk-public-share-auth-sidebar');

// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => "app", 'class' => 'nc-enable-screensharing-extension']);

$this->publishInitialStateForGuest();
}

}
73 changes: 73 additions & 0 deletions lib/TInitialState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.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\Talk;


use OC\User\NoUserException;
use OCP\App\IAppManager;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IUser;
use OCP\Util;

trait TInitialState {

/** @var Config */
protected $talkConfig;
/** @var IConfig */
protected $serverConfig;
/** @var IInitialStateService */
protected $initialStateService;

protected function publishInitialStateShared(): void {
// Needed to enable the screensharing extension in Chromium < 72.
Util::addHeader('meta', ['id' => 'app', 'class' => 'nc-enable-screensharing-extension']);

$this->initialStateService->provideInitialState(
'talk', 'prefer_h264',
$this->serverConfig->getAppValue('spreed', 'prefer_h264', 'no') === 'yes'
);
}

protected function publishInitialStateForUser(IUser $user, IAppManager $appManager): void {

$this->publishInitialStateShared();

$this->initialStateService->provideInitialState(
'talk', 'circles_enabled',
$appManager->isEnabledForUser('circles', $user)
);
}

protected function publishInitialStateForGuest(): void {

$this->publishInitialStateShared();

$this->initialStateService->provideInitialState(
'talk', 'circles_enabled',
false
);
}
}