Skip to content

Commit

Permalink
fix: use autocomplete api to respect settings
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Nov 8, 2024
1 parent 33b82b4 commit e104f5c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/Controller/MentionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit e104f5c

Please sign in to comment.