1414use OCP \AppFramework \Http \Attribute \UserRateLimit ;
1515use OCP \AppFramework \Http \DataResponse ;
1616use OCP \AppFramework \Utility \ITimeFactory ;
17+ use OCP \Collaboration \Collaborators \ISearch ;
1718use OCP \Files \IRootFolder ;
1819use OCP \IRequest ;
1920use OCP \IUserManager ;
2021use OCP \Notification \IManager ;
22+ use OCP \Share \IShare ;
2123
2224class 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 ,
0 commit comments