Skip to content

Commit

Permalink
display type/owner on collaborator search
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jul 28, 2020
1 parent 4cea224 commit 075b60c
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/Collaboration/v1/CollaboratorSearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,40 @@

namespace OCA\Circles\Collaboration\v1;

use OC\User\NoUserException;
use OCA\Circles\Api\v1\Circles;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\MiscService;
use OCP\AppFramework\QueryException;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IL10N;
use OCP\Share;

class CollaboratorSearchPlugin implements ISearchPlugin {


/** @var IL10N */
private $l10n;

/** @var MiscService */
private $miscService;


/**
* CollaboratorSearchPlugin constructor.
*
* @throws QueryException
*/
public function __construct() {
$this->l10n = \OC::$server->getL10N(Application::APP_NAME);
$this->miscService = \OC::$server->query(MiscService::class);
}


/**
* {@inheritdoc}
*/
Expand All @@ -46,7 +69,12 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

$circles = Circles::listCircles(Circle::CIRCLES_ALL, $search, Member::LEVEL_MEMBER);
foreach ($circles as $circle) {
$entry = $this->addResultEntry($circle);
try {
$entry = $this->addResultEntry($circle);
} catch (NoUserException $e) {
continue;
}

if (strtolower($circle->getName()) === strtolower($search)) {
$exact[] = $entry;
} else {
Expand All @@ -63,11 +91,20 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
* @param Circle $circle
*
* @return array
* @throws NoUserException
*/
private function addResultEntry(Circle $circle) {

return [
'label' => $circle->getName(),
'label' => sprintf(
'%s (%s, %s)',
$circle->getName(),
$this->l10n->t($circle->getTypeLongString()),
$this->miscService->getDisplayName(
$circle->getOwner()
->getUserId(), true
)
),
'value' => [
'shareType' => Share::SHARE_TYPE_CIRCLE,
'shareWith' => $circle->getUniqueId(),
Expand Down

0 comments on commit 075b60c

Please sign in to comment.