88namespace OC \User ;
99
1010use OC \Hooks \PublicEmitter ;
11+ use OC \KnownUser \KnownUserService ;
1112use OC \Memcache \WithLocalCache ;
1213use OCP \Config \IUserConfig ;
1314use OCP \DB \QueryBuilder \IQueryBuilder ;
@@ -69,6 +70,9 @@ class Manager extends PublicEmitter implements IUserManager {
6970
7071 private DisplayNameCache $ displayNameCache ;
7172
73+ // These services cannot be injected through DI because user manager is used early in install process
74+ private ?KnownUserService $ knownUserService = null ;
75+
7276 // This constructor can't autoload any class requiring a DB connection.
7377 public function __construct (
7478 private IConfig $ config ,
@@ -83,6 +87,10 @@ public function __construct(
8387 $ this ->displayNameCache = new DisplayNameCache ($ cacheFactory , $ this );
8488 }
8589
90+ private function getKnownUserService (): KnownUserService {
91+ return $ this ->knownUserService ??= Server::get (KnownUserService::class);
92+ }
93+
8694 /**
8795 * Get the active backends
8896 * @return UserInterface[]
@@ -362,7 +370,12 @@ public function searchKnownUsersByDisplayName(string $searcher, string $pattern,
362370 $ backendUsers = $ backend ->searchKnownUsersByDisplayName ($ searcher , $ pattern , $ limit , $ offset );
363371 } else {
364372 // Better than nothing, but filtering after pagination can remove lots of results.
365- $ backendUsers = $ backend ->getDisplayNames ($ pattern , $ limit , $ offset );
373+ $ backendUsers = array_filter (
374+ $ backend ->getDisplayNames ($ pattern , $ limit , $ offset ),
375+ fn (string $ uid ): bool => $ this ->getKnownUserService ()->isKnownToUser ($ searcher , $ uid ),
376+ ARRAY_FILTER_USE_KEY ,
377+ );
378+
366379 }
367380 if (is_array ($ backendUsers )) {
368381 foreach ($ backendUsers as $ uid => $ displayName ) {
0 commit comments