Skip to content

Commit

Permalink
Merge pull request #26033 from nextcloud/enh/comments/to_initialstate
Browse files Browse the repository at this point in the history
Move comments to initial state
  • Loading branch information
ChristophWurst authored Mar 23, 2021
2 parents 9c9cac6 + 8988406 commit 24ec924
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 126 deletions.
2 changes: 1 addition & 1 deletion apps/comments/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
'OCA\\Comments\\Collaboration\\CommentersSorter' => $baseDir . '/../lib/Collaboration/CommentersSorter.php',
'OCA\\Comments\\Controller\\Notifications' => $baseDir . '/../lib/Controller/Notifications.php',
'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php',
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => $baseDir . '/../lib/Listener/CommentsEntityEventListener.php',
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Listener\\LoadSidebarScripts' => $baseDir . '/../lib/Listener/LoadSidebarScripts.php',
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => $baseDir . '/../lib/MaxAutoCompleteResultsInitialState.php',
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\CommentsSearchProvider' => $baseDir . '/../lib/Search/CommentsSearchProvider.php',
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ComposerStaticInitComments
'OCA\\Comments\\Collaboration\\CommentersSorter' => __DIR__ . '/..' . '/../lib/Collaboration/CommentersSorter.php',
'OCA\\Comments\\Controller\\Notifications' => __DIR__ . '/..' . '/../lib/Controller/Notifications.php',
'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php',
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => __DIR__ . '/..' . '/../lib/Listener/CommentsEntityEventListener.php',
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Listener\\LoadSidebarScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarScripts.php',
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => __DIR__ . '/..' . '/../lib/MaxAutoCompleteResultsInitialState.php',
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\CommentsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/CommentsSearchProvider.php',
Expand Down
56 changes: 28 additions & 28 deletions apps/comments/js/comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/comments/js/comments-app.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/comments/js/comments.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/comments/js/comments.js.map

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions apps/comments/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
use OCA\Comments\Capabilities;
use OCA\Comments\Controller\Notifications;
use OCA\Comments\EventHandler;
use OCA\Comments\JSSettingsHelper;
use OCA\Comments\Listener\CommentsEntityEventListener;
use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\MaxAutoCompleteResultsInitialState;
use OCA\Comments\Notification\Notifier;
use OCA\Comments\Search\LegacyProvider;
use OCA\Comments\Search\CommentsSearchProvider;
Expand All @@ -45,10 +45,8 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
use OCP\IConfig;
use OCP\ISearch;
use OCP\IServerContainer;
use OCP\Util;

class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
Expand All @@ -75,15 +73,14 @@ public function register(IRegistrationContext $context): void {
CommentsEntityEventListener::class
);
$context->registerSearchProvider(CommentsSearchProvider::class);

$context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
}

public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'registerNotifier']));
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));

$jsSettingsHelper = new JSSettingsHelper($context->getAppContainer()->get(IConfig::class));
Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');

$context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
* @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -24,22 +26,23 @@

namespace OCA\Comments;

use OCP\AppFramework\Services\InitialStateProvider;
use OCP\IConfig;

class JSSettingsHelper {
class MaxAutoCompleteResultsInitialState extends InitialStateProvider {

/** @var IConfig */
private $c;
private $config;

public function __construct(IConfig $c) {
$this->c = $c;
public function __construct(IConfig $config) {
$this->config = $config;
}

public function extend(array $settings) {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);

$value = (int)$this->c->getAppValue('comments', 'maxAutoCompleteResults', 10);
$appConfig['comments']['maxAutoCompleteResults'] = $value;
public function getKey(): string {
return 'maxAutoCompleteResults';
}

$settings['array']['oc_appconfig'] = json_encode($appConfig);
public function getData(): int {
return (int)$this->config->getAppValue('comments', 'maxAutoCompleteResults', '10');
}
}
3 changes: 2 additions & 1 deletion apps/comments/src/views/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<script>
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import VTooltip from 'v-tooltip'
import Vue from 'vue'
Expand Down Expand Up @@ -226,7 +227,7 @@ export default {
itemType: 'files',
itemId: this.ressourceId,
sorter: 'commenters|share-recipients',
limit: OC.appConfig?.comments?.maxAutoCompleteResults || 25,
limit: loadState('comment', 'maxAutoCompleteResults'),
},
})
return callback(results.data.ocs.data)
Expand Down
73 changes: 0 additions & 73 deletions apps/comments/tests/Unit/JSSettingsHelperTest.php

This file was deleted.

0 comments on commit 24ec924

Please sign in to comment.