Skip to content

Commit 9e0158d

Browse files
authored
Merge pull request #4210 from nextcloud/fix/mention-autocomplete
feat: use autocomplete api for mentions
2 parents cb86d80 + 1d4c813 commit 9e0158d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/Controller/MentionController.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1515
use OCP\AppFramework\Http\DataResponse;
1616
use OCP\AppFramework\Utility\ITimeFactory;
17+
use OCP\Collaboration\Collaborators\ISearch;
1718
use OCP\Files\IRootFolder;
1819
use OCP\IRequest;
1920
use OCP\IUserManager;
2021
use OCP\Notification\IManager;
22+
use OCP\Share\IShare;
2123

2224
class MentionController extends Controller {
2325
public function __construct(
@@ -27,6 +29,7 @@ public function __construct(
2729
private IManager $manager,
2830
private ITimeFactory $timeFactory,
2931
private IUserManager $userManager,
32+
private ISearch $collaboratorSearch,
3033
private ?string $userId,
3134
) {
3235
parent::__construct($appName, $request);
@@ -41,22 +44,21 @@ public function mention(int $fileId, string $mention): DataResponse {
4144
return new DataResponse(['message' => 'File not found for current user'], Http::STATUS_NOT_FOUND);
4245
}
4346

44-
// Reverse the array of users to pop off the first user later
45-
$userResults = array_reverse($this->userManager->searchDisplayName($mention, 1));
46-
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) {
4750
return new DataResponse([], Http::STATUS_NOT_FOUND);
4851
}
49-
50-
// Get the first user returned in the array
51-
$user = array_pop($userResults);
52-
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
52+
53+
$user = array_pop($matchedUsers);
54+
$userFolder = $this->rootFolder->getUserFolder($user['value']['shareWith']);
5355
$file = $userFolder->getFirstNodeById($fileId);
5456
if ($file === null) {
5557
return new DataResponse(['message' => 'File not found for mentioned user'], Http::STATUS_NOT_FOUND);
5658
}
5759

5860
$notification = $this->manager->createNotification();
59-
$notification->setUser($user->getUID())
61+
$notification->setUser($user['value']['shareWith'])
6062
->setApp(Application::APPNAME)
6163
->setSubject(Notifier::TYPE_MENTIONED, [
6264
Notifier::SUBJECT_MENTIONED_SOURCE_USER => $this->userId,

src/mixins/uiMention.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default {
2727
const list = users.map((user) => {
2828
const profile = window.location.protocol + '//' + getNextcloudUrl() + '/index.php/u/' + user.id
2929
return {
30-
username: user.label,
30+
label: user.label,
31+
username: user.id,
3132
profile,
3233
}
3334
})

0 commit comments

Comments
 (0)