1414use OCP \AppFramework \Http \Attribute \UserRateLimit ;
1515use OCP \AppFramework \Http \DataResponse ;
1616use OCP \AppFramework \Utility \ITimeFactory ;
17- use OCP \Files \IRootFolder ;
1817use OCP \Collaboration \Collaborators \ISearch ;
18+ use OCP \Files \IRootFolder ;
1919use OCP \IRequest ;
2020use OCP \IUserManager ;
2121use OCP \Notification \IManager ;
@@ -29,7 +29,7 @@ public function __construct(
2929 private IManager $ manager ,
3030 private ITimeFactory $ timeFactory ,
3131 private IUserManager $ userManager ,
32- private ISearch $ search ,
32+ private ISearch $ collaboratorSearch ,
3333 private ?string $ userId ,
3434 ) {
3535 parent ::__construct ($ appName , $ request );
@@ -44,25 +44,21 @@ public function mention(int $fileId, string $mention): DataResponse {
4444 return new DataResponse ([], Http::STATUS_NOT_FOUND );
4545 }
4646
47- [$ results , ] = $ this ->search ->search ($ mention , [IShare::TYPE_USER ], false , 20 , 0 );
48- return new DataResponse ($ results , Http::STATUS_OK );
49-
50- // Reverse the array of users to pop off the first user later
51- $ userResults = array_reverse ($ this ->userManager ->searchDisplayName ($ mention , 1 ));
52- 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 ) {
5350 return new DataResponse ([], Http::STATUS_NOT_FOUND );
5451 }
55-
56- // Get the first user returned in the array
57- $ user = array_pop ($ userResults );
58- $ userFolder = $ this ->rootFolder ->getUserFolder ($ user ->getUID ());
52+
53+ $ user = array_pop ($ matchedUsers );
54+ $ userFolder = $ this ->rootFolder ->getUserFolder ($ user ['shareWithDisplayNameUnique ' ]);
5955 $ file = $ userFolder ->getFirstNodeById ($ fileId );
6056 if ($ file === null ) {
6157 return new DataResponse ([], Http::STATUS_NOT_FOUND );
6258 }
6359
6460 $ notification = $ this ->manager ->createNotification ();
65- $ notification ->setUser ($ user-> getUID () )
61+ $ notification ->setUser ($ user[ ' shareWithDisplayNameUnique ' ] )
6662 ->setApp (Application::APPNAME )
6763 ->setSubject (Notifier::TYPE_MENTIONED , [
6864 Notifier::SUBJECT_MENTIONED_SOURCE_USER => $ this ->userId ,
0 commit comments