summaryrefslogtreecommitdiffstats
path: root/lib/private/User/Manager.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-03-17 09:02:37 +0100
committerJoas Schilling <coding@schilljs.com>2021-03-17 09:51:31 +0100
commit9a189bc710a971bea5edb4807914a3978356e66b (patch)
treec9451bc47f58b1eb61459b1d7a7b6006ec65d095 /lib/private/User/Manager.php
parentf82edda9c190462132f5042a177e7fa413291330 (diff)
downloadnextcloud-server-9a189bc710a971bea5edb4807914a3978356e66b.tar.gz
nextcloud-server-9a189bc710a971bea5edb4807914a3978356e66b.zip
Improve search results when only phonebook-matches can we autocompleted
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/User/Manager.php')
-rw-r--r--lib/private/User/Manager.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index 036d2703d35..64aa5e1d22b 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -47,6 +47,7 @@ use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\Support\Subscription\IRegistry;
use OCP\User\Backend\IGetRealUIDBackend;
+use OCP\User\Backend\ISearchKnownUsersBackend;
use OCP\User\Events\BeforeUserCreatedEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\UserInterface;
@@ -330,6 +331,41 @@ class Manager extends PublicEmitter implements IUserManager {
}
/**
+ * Search known users (from phonebook sync) by displayName
+ *
+ * @param string $searcher
+ * @param string $pattern
+ * @param int|null $limit
+ * @param int|null $offset
+ * @return IUser[]
+ */
+ public function searchKnownUsersByDisplayName(string $searcher, string $pattern, ?int $limit = null, ?int $offset = null): array {
+ $users = [];
+ foreach ($this->backends as $backend) {
+ if ($backend instanceof ISearchKnownUsersBackend) {
+ $backendUsers = $backend->searchKnownUsersByDisplayName($searcher, $pattern, $limit, $offset);
+ } else {
+ // Better than nothing, but filtering after pagination can remove lots of results.
+ $backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
+ }
+ if (is_array($backendUsers)) {
+ foreach ($backendUsers as $uid => $displayName) {
+ $users[] = $this->getUserObject($uid, $backend);
+ }
+ }
+ }
+
+ usort($users, function ($a, $b) {
+ /**
+ * @var IUser $a
+ * @var IUser $b
+ */
+ return strcasecmp($a->getDisplayName(), $b->getDisplayName());
+ });
+ return $users;
+ }
+
+ /**
* @param string $uid
* @param string $password
* @throws \InvalidArgumentException