From ab1c26f69c9bc8c65ac2cc4590956fb732cb2b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 19 Nov 2018 21:54:26 +0100 Subject: [PATCH] Implement social app setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/routes.php | 6 ++- lib/Controller/ConfigController.php | 61 +++++++++++++++++++++++++ lib/Controller/NavigationController.php | 18 ++++++-- lib/Service/ConfigService.php | 10 ++++ src/App.vue | 38 +++++++++++++-- src/store/settings.js | 3 ++ src/store/timeline.js | 5 +- src/views/Timeline.vue | 12 ++++- 8 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 lib/Controller/ConfigController.php diff --git a/appinfo/routes.php b/appinfo/routes.php index 1dd4f1c5..6cb2f462 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -42,7 +42,9 @@ return [ ['name' => 'Local#accountsSearch', 'url' => '/api/v1/accounts/search', 'verb' => 'GET'], ['name' => 'Local#accountFollow', 'url' => '/api/v1/account/follow', 'verb' => 'PUT'], ['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'], - ['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'] + ['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'], - ] + ['name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress', 'verb' => 'POST'], + +] ]; diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php new file mode 100644 index 00000000..dc2ee989 --- /dev/null +++ b/lib/Controller/ConfigController.php @@ -0,0 +1,61 @@ + + * + * @author Julius Härtl + * + * @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\Social\Controller; + +use OCA\Activity\Data; +use OCA\Social\Exceptions\SocialAppConfigException; +use OCA\Social\Service\ConfigService; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; + + +class ConfigController extends Controller { + + private $configService; + + public function __construct(string $appName, IRequest $request, ConfigService $configService) { + parent::__construct($appName, $request); + + $this->configService = $configService; + } + + /** + * @param string $cloudAddress + * @return DataResponse + */ + public function setCloudAddress(string $cloudAddress): DataResponse { + try { + $this->configService->setCloudAddress($cloudAddress); + return new DataResponse([]); + } catch (SocialAppConfigException $e) { + return new DataResponse([ + 'message' => $e->getMessage() + ], Http::STATUS_BAD_REQUEST); + } + } +} \ No newline at end of file diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index e19e9ff2..c0de31ec 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -122,14 +122,24 @@ class NavigationController extends Controller { 'serverData' => [ 'public' => false, 'firstrun' => false, - 'setup' => false + 'setup' => false, ] ]; try { - $this->configService->getCloudAddress(); - $data['serverData']['setup'] = true; + $data['serverData']['cloudAddress'] = $this->configService->getCloudAddress(); } catch (SocialAppConfigException $e) { + $data['serverData']['setup'] = true; + $data['serverData']['isAdmin'] = \OC::$server->getGroupManager()->isAdmin($this->userId); + if ($data['serverData']['isAdmin']) { + $cloudAddress = $this->request->getParam('cloudAddress'); + if ($cloudAddress !== null) { + $this->configService->setCloudAddress($cloudAddress); + } else { + $data['serverData']['cliUrl'] = $this->config->getSystemValue('overwrite.cli.url', \OC::$server->getURLGenerator()->getBaseUrl()); + return new TemplateResponse(Application::APP_NAME, 'setup', $data); + } + } } try { @@ -143,6 +153,8 @@ class NavigationController extends Controller { } + + /** * Display the navigation page of the Social app. * diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 66e88c68..4ecaa335 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -210,6 +210,16 @@ class ConfigService { return $this->config->getSystemValue($key, ''); } + /** + * @param bool $host + * + * @return string + * @throws SocialAppConfigException + */ + public function setCloudAddress(string $cloudAddress) { + // TODO: Validate + $this->setAppValue(self::SOCIAL_ADDRESS, $cloudAddress); + } /** * @param bool $host diff --git a/src/App.vue b/src/App.vue index b3351435..15457f61 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,5 @@ + \ No newline at end of file diff --git a/src/store/settings.js b/src/store/settings.js index 75ac7972..a5b2efc0 100644 --- a/src/store/settings.js +++ b/src/store/settings.js @@ -26,6 +26,9 @@ const state = { const mutations = { setServerData(state, data) { state.serverData = data + }, + setServerDataEntry(state, key, value) { + state.serverData[key] = value; } } const getters = { diff --git a/src/store/timeline.js b/src/store/timeline.js index 0b633974..e18b2746 100644 --- a/src/store/timeline.js +++ b/src/store/timeline.js @@ -49,8 +49,11 @@ const actions = { fetchTimeline(context, account) { const sinceTimestamp = Date.parse(state.since)/1000; return axios.get(OC.generateUrl('apps/social/api/v1/timeline?limit=5&since=' + sinceTimestamp)).then((response) => { + if (response.status === -1) { + throw response.message; + } context.commit('addToTimeline', response.data.result); - return response.data.result; + return response.data; }) } } diff --git a/src/views/Timeline.vue b/src/views/Timeline.vue index 60dd52e4..23448bac 100644 --- a/src/views/Timeline.vue +++ b/src/views/Timeline.vue @@ -244,7 +244,17 @@ export default { infiniteHandler($state) { this.$store.dispatch('fetchTimeline', { account: this.currentUser.uid - }).then((response) => { response.length > 0 ? $state.loaded() : $state.complete() }); + }).then((response) => { + if (response.status = -1) { + OC.Notification.showTemporary('Failed to load more timeline entries'); + console.error('Failed to load more timeline entries', response); + $state.complete(); + return; + } + response.results.length > 0 ? $state.loaded() : $state.complete() + }).catch((error) => { + + }); }, } }