diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-08-30 10:56:02 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-22 14:13:32 +0200 |
commit | fd6daf8d195b985fcdec82c0c53e8ba230765f41 (patch) | |
tree | dbfbbfb8424604daeb0fba63a8e0d2b7cda9a3ac /lib/private | |
parent | 2b31b8289169e35be7bb1b129e9a978ddcd8f478 (diff) | |
download | nextcloud-server-fd6daf8d195b985fcdec82c0c53e8ba230765f41.tar.gz nextcloud-server-fd6daf8d195b985fcdec82c0c53e8ba230765f41.zip |
AutoCompletion backend
* introduce a Controller for requests
* introduce result sorting mechanism
* extend Comments to retrieve commentors (actors) in a tree
* add commenters sorter
* add share recipients sorter
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Collaboration/AutoComplete/Manager.php | 81 | ||||
-rw-r--r-- | lib/private/Comments/Manager.php | 65 | ||||
-rw-r--r-- | lib/private/Server.php | 12 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 2 |
5 files changed, 161 insertions, 1 deletions
diff --git a/lib/private/Collaboration/AutoComplete/Manager.php b/lib/private/Collaboration/AutoComplete/Manager.php new file mode 100644 index 00000000000..f801ea23338 --- /dev/null +++ b/lib/private/Collaboration/AutoComplete/Manager.php @@ -0,0 +1,81 @@ +<?php +/** + * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @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 OC\Collaboration\AutoComplete; + +use OCP\Collaboration\AutoComplete\IManager; +use OCP\Collaboration\AutoComplete\ISorter; +use OCP\IServerContainer; + +class Manager implements IManager { + /** @var string[] */ + protected $sorters =[]; + + /** @var ISorter[] */ + protected $sorterInstances = []; + /** @var IServerContainer */ + private $c; + + public function __construct(IServerContainer $container) { + $this->c = $container; + } + + public function runSorters(array $sorters, array &$sortArray, array $context) { + $sorterInstances = $this->getSorters(); + while($sorter = array_shift($sorters)) { + if(isset($sorterInstances[$sorter])) { + $sorterInstances[$sorter]->sort($sortArray, $context); + } else { + $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ + 'app' => 'core', 'id' => $sorter + ]); + } + } + } + + public function registerSorter($className) { + $sorters[] = $className; + } + + protected function getSorters() { + if(count($this->sorterInstances) === 0) { + foreach ($this->sorters as $sorter) { + /** @var ISorter $instance */ + $instance = $this->c->resolve($sorter); + if(!$instance instanceof ISorter) { + $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', + ['app' => 'core', 'class' => $sorter]); + continue; + } + $sorterId = trim($instance->getId()); + if(trim($sorterId) === '') { + $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', + ['app' => 'core', 'class' => $sorter]); + continue; + } + $this->sorterInstances[$sorterId] = $instance; + } + } + return $this->sorterInstances; + } +} diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 078e1eef4d3..a6b2102da67 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -318,6 +318,71 @@ class Manager implements ICommentsManager { } /** + * Get the actor types and ID that commented in the tree specified by the ID + * + * @param string $id + * @return array + * @since 13.0.0 + * + * The return array looks like this: + * + * [ + * 'user' => [ + * 'alice' => 2, + * 'bob' => 3 + * ], + * 'robot' => [ + * 'r2-d2' => 5, + * 'c-3po' => 17, + * ] + * ] + */ + public function getActorsInTree($id) { + $tree = $this->getTree($id); + $actors = []; + $this->extractActor($tree, $actors); + return $actors; + } + + /** + * @param array $node + * @param array &$actors + * + * build an array that looks like: + * + * [ + * 'user' => [ + * 'alice' => 2, + * 'bob' => 3 + * ], + * 'robot' => [ + * 'r2-d2' => 5, + * 'c-3po' => 17, + * ] + * ] + * + */ + protected function extractActor(array $node, array &$actors) { + if(isset($node['replies'])) { + foreach ($node['replies'] as $subNode) { + $this->extractActor($subNode, $actors); + } + } + if(isset($node['comment']) && $node['comment'] instanceof IComment) { + /** @var IComment $comment */ + $comment = $node['comment']; + if(!isset($actors[$comment->getActorType()])) { + $actors[$comment->getActorType()] = []; + } + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { + $actors[$comment->getActorType()][$comment->getActorId()] = 1; + } else { + $actors[$comment->getActorType()][$comment->getActorId()] += 1; + } + } + } + + /** * returns comments for a specific object (e.g. a file). * * The sort order is always newest to oldest. diff --git a/lib/private/Server.php b/lib/private/Server.php index 29aee06d896..c03b7e04606 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1011,6 +1011,11 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); + $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) { + return new Collaboration\AutoComplete\Manager($c); + }); + $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class); + $this->registerService('SettingsManager', function (Server $c) { $manager = new \OC\Settings\Manager( $c->getLogger(), @@ -1802,6 +1807,13 @@ class Server extends ServerContainer implements IServerContainer { } /** + * @return \OCP\Collaboration\AutoComplete\IManager + */ + public function getAutoCompleteManager(){ + return $this->query('AutoCompleteManager'); + } + + /** * Returns the LDAP Provider * * @return \OCP\LDAP\ILDAPProvider diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 42f2170122e..9245b9d4f51 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1322,7 +1322,7 @@ class Manager implements IManager { * * @param \OCP\Files\Node $path * @param bool $recursive Should we check all parent folders as well - * @param bool $currentAccess Should the user have currently access to the file + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) * @return array */ public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index bd261b05e51..efa2afd7356 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -185,6 +185,8 @@ class OC_App { 'class' => $plugin['@value'], ]; \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); } } } |