Skip to content

Commit e104f5c

Browse files
committed
fix: use autocomplete api to respect settings
Signed-off-by: Elizabeth Danzberger <[email protected]>
1 parent 33b82b4 commit e104f5c

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

lib/Controller/MentionController.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1515
use OCP\AppFramework\Http\DataResponse;
1616
use OCP\AppFramework\Utility\ITimeFactory;
17-
use OCP\Files\IRootFolder;
1817
use OCP\Collaboration\Collaborators\ISearch;
18+
use OCP\Files\IRootFolder;
1919
use OCP\IRequest;
2020
use OCP\IUserManager;
2121
use OCP\Notification\IManager;
@@ -29,7 +29,7 @@ public function __construct(
2929
private IManager $manager,
3030
private ITimeFactory $timeFactory,
3131
private IUserManager $userManager,
32-
private ISearch $search,
32+
private ISearch $collaboratorSearch,
3333
private ?string $userId,
3434
) {
3535
parent::__construct($appName, $request);
@@ -44,25 +44,21 @@ public function mention(int $fileId, string $mention): DataResponse {
4444
return new DataResponse([], Http::STATUS_NOT_FOUND);
4545
}
4646

47-
[$results, ] = $this->search->search($mention, [IShare::TYPE_USER], false, 20, 0);
48-
return new DataResponse($results, Http::STATUS_OK);
49-
50-
// Reverse the array of users to pop off the first user later
51-
$userResults = array_reverse($this->userManager->searchDisplayName($mention, 1));
52-
if (count($userResults) < 1) {
47+
[$searchResults, ] = $this->collaboratorSearch->search($mention, [IShare::TYPE_USER], false, 1, 0);
48+
$matchedUsers = $searchResults['exact']['users'];
49+
if (count($matchedUsers) < 1) {
5350
return new DataResponse([], Http::STATUS_NOT_FOUND);
5451
}
55-
56-
// Get the first user returned in the array
57-
$user = array_pop($userResults);
58-
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
52+
53+
$user = array_pop($matchedUsers);
54+
$userFolder = $this->rootFolder->getUserFolder($user['shareWithDisplayNameUnique']);
5955
$file = $userFolder->getFirstNodeById($fileId);
6056
if ($file === null) {
6157
return new DataResponse([], Http::STATUS_NOT_FOUND);
6258
}
6359

6460
$notification = $this->manager->createNotification();
65-
$notification->setUser($user->getUID())
61+
$notification->setUser($user['shareWithDisplayNameUnique'])
6662
->setApp(Application::APPNAME)
6763
->setSubject(Notifier::TYPE_MENTIONED, [
6864
Notifier::SUBJECT_MENTIONED_SOURCE_USER => $this->userId,

0 commit comments

Comments
 (0)