Skip to content

Commit

Permalink
Merge pull request #4210 from nextcloud/fix/mention-autocomplete
Browse files Browse the repository at this point in the history
feat: use autocomplete api for mentions
  • Loading branch information
juliusknorr authored Dec 13, 2024
2 parents cb86d80 + 1d4c813 commit 9e0158d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 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(['message' => 'File not found for current user'], 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(['message' => 'File not found for mentioned user'], 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
3 changes: 2 additions & 1 deletion src/mixins/uiMention.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default {
const list = users.map((user) => {
const profile = window.location.protocol + '//' + getNextcloudUrl() + '/index.php/u/' + user.id
return {
username: user.label,
label: user.label,
username: user.id,
profile,
}
})
Expand Down

0 comments on commit 9e0158d

Please sign in to comment.