Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-04-09 14:44:27 +0300
committerJoas Schilling <coding@schilljs.com>2020-04-27 23:49:15 +0300
commit9ea0f5bcfaaa7a0aea4fffbf60d3b7ae2e29af43 (patch)
tree80d082cdc9e2b88dcf8fd4c03845a8ddca0b62d9 /lib/TInitialState.php
parentae35aa7f92d622bb80bcb27389ee1a09b1a57090 (diff)
Create the initialState in a single location
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/TInitialState.php')
-rw-r--r--lib/TInitialState.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/lib/TInitialState.php b/lib/TInitialState.php
new file mode 100644
index 000000000..4c8c2853b
--- /dev/null
+++ b/lib/TInitialState.php
@@ -0,0 +1,106 @@
+<?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, IRootFolder $rootFolder, IAppManager $appManager): void {
+
+ $this->publishInitialStateShared();
+
+ $this->initialStateService->provideInitialState(
+ 'talk', 'start_conversations',
+ !$this->talkConfig->isNotAllowedToCreateConversations($user)
+ );
+
+ $this->initialStateService->provideInitialState(
+ 'talk', 'circles_enabled',
+ $appManager->isEnabledForUser('circles', $user)
+ );
+
+ $attachmentFolder = $this->talkConfig->getAttachmentFolder($user->getUID());
+ $this->initialStateService->provideInitialState(
+ 'talk', 'attachment_folder',
+ $attachmentFolder
+ );
+
+ if ($attachmentFolder) {
+ try {
+ $userFolder = $rootFolder->getUserFolder($user->getUID());
+
+ if (!$userFolder->nodeExists($attachmentFolder)) {
+ $userFolder->newFolder($attachmentFolder);
+ }
+ } catch (NotPermittedException $e) {
+ } catch (NoUserException $e) {
+ }
+ }
+ }
+
+ protected function publishInitialStateForGuest(): void {
+
+ $this->publishInitialStateShared();
+
+ $this->initialStateService->provideInitialState(
+ 'talk', 'start_conversations',
+ false
+ );
+
+ $this->initialStateService->provideInitialState(
+ 'talk', 'circles_enabled',
+ false
+ );
+
+ $this->initialStateService->provideInitialState(
+ 'talk', 'attachment_folder',
+ ''
+ );
+ }
+}