diff --git a/lib/Controller/MentionController.php b/lib/Controller/MentionController.php index 8c03927ffd..39f90709e5 100644 --- a/lib/Controller/MentionController.php +++ b/lib/Controller/MentionController.php @@ -14,8 +14,8 @@ use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\Files\IRootFolder; use OCP\Collaboration\Collaborators\ISearch; +use OCP\Files\IRootFolder; use OCP\IRequest; use OCP\IUserManager; use OCP\Notification\IManager; @@ -29,7 +29,7 @@ public function __construct( private IManager $manager, private ITimeFactory $timeFactory, private IUserManager $userManager, - private ISearch $search, + private ISearch $collaboratorSearch, private ?string $userId, ) { parent::__construct($appName, $request); @@ -44,25 +44,21 @@ public function mention(int $fileId, string $mention): DataResponse { return new DataResponse([], Http::STATUS_NOT_FOUND); } - [$results, ] = $this->search->search($mention, [IShare::TYPE_USER], false, 20, 0); - return new DataResponse($results, Http::STATUS_OK); - - // Reverse the array of users to pop off the first user later - $userResults = array_reverse($this->userManager->searchDisplayName($mention, 1)); - if (count($userResults) < 1) { + [$searchResults, ] = $this->collaboratorSearch->search($mention, [IShare::TYPE_USER], false, 1, 0); + $matchedUsers = $searchResults['exact']['users']; + if (count($matchedUsers) < 1) { return new DataResponse([], Http::STATUS_NOT_FOUND); } - - // Get the first user returned in the array - $user = array_pop($userResults); - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); + + $user = array_pop($matchedUsers); + $userFolder = $this->rootFolder->getUserFolder($user['shareWithDisplayNameUnique']); $file = $userFolder->getFirstNodeById($fileId); if ($file === null) { return new DataResponse([], Http::STATUS_NOT_FOUND); } $notification = $this->manager->createNotification(); - $notification->setUser($user->getUID()) + $notification->setUser($user['shareWithDisplayNameUnique']) ->setApp(Application::APPNAME) ->setSubject(Notifier::TYPE_MENTIONED, [ Notifier::SUBJECT_MENTIONED_SOURCE_USER => $this->userId,