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 <lizzy7128@tutanota.de>
  • Loading branch information
elzody committed Nov 13, 2024
1 parent b42ef92 commit 7600e7e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/Controller/MentionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\Collaborators\ISearch;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\Share\IShare;

class MentionController extends Controller {
public function __construct(
Expand All @@ -27,6 +29,7 @@ public function __construct(
private IManager $manager,
private ITimeFactory $timeFactory,
private IUserManager $userManager,
private ISearch $collaboratorSearch,
private ?string $userId,
) {
parent::__construct($appName, $request);
Expand All @@ -41,22 +44,21 @@ public function mention(int $fileId, string $mention): DataResponse {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

// 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['value']['shareWith']);
$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['value']['shareWith'])
->setApp(Application::APPNAME)
->setSubject(Notifier::TYPE_MENTIONED, [
Notifier::SUBJECT_MENTIONED_SOURCE_USER => $this->userId,
Expand Down

0 comments on commit 7600e7e

Please sign in to comment.