Skip to content

Commit

Permalink
fix: mention search issues
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Sep 28, 2022
1 parent 2fb9c77 commit 3a81d1c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/Controller/UserApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

class UserApiController extends ApiController {
private ISearch $collaboratorSearch;
Expand Down Expand Up @@ -44,24 +45,25 @@ public function index(int $documentId, int $sessionId, string $sessionToken, str
foreach ($sessions as $session) {
$sessionUserId = $session['userId'];
if ($sessionUserId !== null && !isset($users[$sessionUserId])) {
$users[$sessionUserId] = $this->userManager->getDisplayName($sessionUserId);
$displayName = $this->userManager->getDisplayName($sessionUserId);
if (stripos($displayName, $filter) !== false) {
$users[$sessionUserId] = $displayName;
}
}
}

$currentSession = $this->sessionService->getSession($documentId, $sessionId, $sessionToken);
if ($currentSession->getUserId() !== null) {
// Add other users to the autocomplete list
[$result] = $this->collaboratorSearch->search($filter, [IShare::TYPE_USER], false, $limit, 0);
$userSearch = array_merge($result['users'], $result['exact']['users']);

foreach ($result['users'] as ['label' => $label, 'value' => $value]) {
foreach ($userSearch as ['label' => $label, 'value' => $value]) {
if (isset($value['shareWith'])) {
$id = $value['shareWith'];
$users[$id] = $label;
}
}

$user = $this->userSession->getUser();
$users[$user->getUID()] = $user->getDisplayName();
}

return new DataResponse($users);
Expand Down

0 comments on commit 3a81d1c

Please sign in to comment.