diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 918684ff..b1b0dcd3 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -8,6 +8,7 @@ declare(strict_types=1); * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * + * @author Jonas Sulzer * @author Maxence Lange * @copyright 2018, Maxence Lange * @license GNU AGPL version 3 or any later version @@ -50,6 +51,7 @@ use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; +use OCP\IInitialStateService; use OCP\IL10N; use OCP\IRequest; use OCP\IURLGenerator; @@ -109,7 +111,7 @@ class NavigationController extends Controller { * @param MiscService $miscService */ public function __construct( - IL10N $l10n, IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator, + IL10N $l10n, IRequest $request, $userId, IConfig $config, IInitialStateService $initialStateService, IURLGenerator $urlGenerator, AccountService $accountService, DocumentService $documentService, ConfigService $configService, CheckService $checkService, MiscService $miscService ) { @@ -118,6 +120,7 @@ class NavigationController extends Controller { $this->userId = $userId; $this->l10n = $l10n; $this->config = $config; + $this->initialStateService = $initialStateService; $this->urlGenerator = $urlGenerator; $this->checkService = $checkService; @@ -141,33 +144,32 @@ class NavigationController extends Controller { * @throws SocialAppConfigException */ public function navigate(string $path = ''): TemplateResponse { - $data = [ - 'serverData' => [ - 'public' => false, - 'firstrun' => false, - 'setup' => false, - 'isAdmin' => OC::$server->getGroupManager() - ->isAdmin($this->userId), - 'cliUrl' => $this->getCliUrl() - ] + $serverData = [ + 'public' => false, + 'firstrun' => false, + 'setup' => false, + 'isAdmin' => OC::$server->getGroupManager() + ->isAdmin($this->userId), + 'cliUrl' => $this->getCliUrl() ]; try { - $data['serverData']['cloudAddress'] = $this->configService->getCloudUrl(); + $serverData['cloudAddress'] = $this->configService->getCloudUrl(); } catch (SocialAppConfigException $e) { $this->checkService->checkInstallationStatus(true); $cloudAddress = $this->setupCloudAddress(); if ($cloudAddress !== '') { - $data['serverData']['cloudAddress'] = $cloudAddress; + $serverData['cloudAddress'] = $cloudAddress; } else { - $data['serverData']['setup'] = true; + $serverData['setup'] = true; - if ($data['serverData']['isAdmin']) { + if ($serverData['isAdmin']) { $cloudAddress = $this->request->getParam('cloudAddress'); if ($cloudAddress !== null) { $this->configService->setCloudUrl($cloudAddress); } else { - return new TemplateResponse(Application::APP_NAME, 'main', $data); + $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData); + return new TemplateResponse(Application::APP_NAME, 'main'); } } } @@ -179,9 +181,9 @@ class NavigationController extends Controller { $this->configService->setSocialUrl(); } - if ($data['serverData']['isAdmin']) { + if ($serverData['isAdmin']) { $checks = $this->checkService->checkDefault(); - $data['serverData']['checks'] = $checks; + $serverData['checks'] = $checks; } /* @@ -189,7 +191,7 @@ class NavigationController extends Controller { */ try { $this->accountService->createActor($this->userId, $this->userId); - $data['serverData']['firstrun'] = true; + $serverData['firstrun'] = true; } catch (AccountAlreadyExistsException $e) { // we do nothing } catch (NoUserException $e) { @@ -198,7 +200,8 @@ class NavigationController extends Controller { // neither. } - return new TemplateResponse(Application::APP_NAME, 'main', $data); + $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData); + return new TemplateResponse(Application::APP_NAME, 'main'); } private function setupCloudAddress(): string { diff --git a/lib/Controller/OStatusController.php b/lib/Controller/OStatusController.php index ad848960..3ca22a34 100644 --- a/lib/Controller/OStatusController.php +++ b/lib/Controller/OStatusController.php @@ -8,6 +8,7 @@ declare(strict_types=1); * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * + * @author Jonas Sulzer * @author Maxence Lange * @copyright 2018, Maxence Lange * @license GNU AGPL version 3 or any later version @@ -44,6 +45,7 @@ use OCA\Social\Service\MiscService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IInitialStateService; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; @@ -83,11 +85,12 @@ class OStatusController extends Controller { * @param IUserSession $userSession */ public function __construct( - IRequest $request, CacheActorService $cacheActorService, AccountService $accountService, + IRequest $request, IInitialStateService $initialStateService, CacheActorService $cacheActorService, AccountService $accountService, CurlService $curlService, MiscService $miscService, IUserSession $userSession ) { parent::__construct(Application::APP_NAME, $request); + $this->initialStateService = $initialStateService; $this->cacheActorService = $cacheActorService; $this->accountService = $accountService; $this->curlService = $curlService; @@ -118,16 +121,15 @@ class OStatusController extends Controller { throw new Exception('Failed to retrieve current user'); } - return new TemplateResponse( - 'social', 'ostatus', [ - 'serverData' => [ - 'account' => $actor->getAccount(), - 'currentUser' => [ - 'uid' => $user->getUID(), - 'displayName' => $user->getDisplayName(), - ] + $this->initialStateService->provideInitialState('social', 'serverData', [ + 'account' => $actor->getAccount(), + 'currentUser' => [ + 'uid' => $user->getUID(), + 'displayName' => $user->getDisplayName(), ] - ], 'guest' + ]); + return new TemplateResponse( + 'social', 'main', 'guest' ); } catch (Exception $e) { return $this->fail($e); @@ -148,13 +150,12 @@ class OStatusController extends Controller { try { $following = $this->accountService->getActor($local); + $this->initialStateService->provideInitialState('social', 'serverData', [ + 'local' => $local, + 'account' => $following->getAccount() + ]); return new TemplateResponse( - 'social', 'ostatus', [ - 'serverData' => [ - 'local' => $local, - 'account' => $following->getAccount() - ] - ], 'guest' + 'social', 'main', 'guest' ); } catch (Exception $e) { return $this->fail($e); diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index 253c9308..8fada3ae 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -8,6 +8,7 @@ declare(strict_types=1); * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * + * @author Jonas Sulzer * @author Maxence Lange * @copyright 2018, Maxence Lange * @license GNU AGPL version 3 or any later version @@ -48,6 +49,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IInitialStateService; use OCP\IL10N; use OCP\IRequest; @@ -98,13 +100,14 @@ class SocialPubController extends Controller { * @param ConfigService $configService */ public function __construct( - $userId, IRequest $request, IL10N $l10n, NavigationController $navigationController, + $userId, IInitialStateService $initialStateService, IRequest $request, IL10N $l10n, NavigationController $navigationController, CacheActorService $cacheActorService, AccountService $accountService, StreamService $streamService, ConfigService $configService ) { parent::__construct(Application::APP_NAME, $request); $this->userId = $userId; + $this->initialStateService = $initialStateService; $this->l10n = $l10n; $this->navigationController = $navigationController; $this->accountService = $accountService; @@ -126,9 +129,6 @@ class SocialPubController extends Controller { return $this->navigationController->navigate(''); } $data = [ - 'serverData' => [ - 'public' => true, - ], 'application' => 'Social' ]; @@ -142,6 +142,10 @@ class SocialPubController extends Controller { } catch (Exception $e) { return $this->fail($e); } + + $this->initialStateService->provideInitialState('social', 'serverData', [ + 'public' => true, + ]); $page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data); $page->setStatus($status); $page->setHeaderTitle($this->l10n->t('Social')); @@ -229,14 +233,14 @@ class SocialPubController extends Controller { $stream = $this->streamService->getStreamById($postId, true); $data = [ 'id' => $postId, - 'item' => $stream, - 'serverData' => [ - 'public' => ($this->userId === null), - ], 'application' => 'Social' ]; - return new TemplateResponse(Application::APP_NAME, 'stream', $data); + $this->initialStateService->provideInitialState(Application::APP_NAME, 'item', $stream ); + $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', [ + 'public' => ($this->userId === null), + ]); + return new TemplateResponse(Application::APP_NAME, 'main', $data); } diff --git a/package.json b/package.json index 096ba37e..f3bbe836 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@babel/runtime": "^7.11.2", "@nextcloud/auth": "^1.3.0", "@nextcloud/axios": "^1.3.3", + "@nextcloud/initial-state": "^1.1.2", "@nextcloud/logger": "^1.1.2", "@nextcloud/vue": "^2.6.1", "he": "^1.2.0", diff --git a/src/App.vue b/src/App.vue index cd2f589f..689d9209 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,10 +1,10 @@ - - + +