aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2020-08-05 10:37:20 +0200
committerGeorg Ehrke <developer@georgehrke.com>2020-08-14 17:04:52 +0200
commit5b26487f142843ad99a663d1ce2223c46a9498b2 (patch)
treeee28708b23007815af072ea5420d3813e70be2e8 /lib/private/Collaboration
parentb13aa660c91873437afec36ef6466ef609b7959c (diff)
downloadnextcloud-server-5b26487f142843ad99a663d1ce2223c46a9498b2.tar.gz
nextcloud-server-5b26487f142843ad99a663d1ce2223c46a9498b2.zip
Expose status via Collaborators API
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'lib/private/Collaboration')
-rw-r--r--lib/private/Collaboration/Collaborators/UserPlugin.php53
1 files changed, 51 insertions, 2 deletions
diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php
index d1f29350734..72368e50521 100644
--- a/lib/private/Collaboration/Collaborators/UserPlugin.php
+++ b/lib/private/Collaboration/Collaborators/UserPlugin.php
@@ -38,6 +38,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;
+use OCP\UserStatus\IManager as IUserStatusManager;
class UserPlugin implements ISearchPlugin {
/* @var bool */
@@ -53,13 +54,29 @@ class UserPlugin implements ISearchPlugin {
private $userSession;
/** @var IUserManager */
private $userManager;
-
- public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
+ /** @var IUserStatusManager */
+ private $userStatusManager;
+
+ /**
+ * UserPlugin constructor.
+ *
+ * @param IConfig $config
+ * @param IUserManager $userManager
+ * @param IGroupManager $groupManager
+ * @param IUserSession $userSession
+ * @param IUserStatusManager $userStatusManager
+ */
+ public function __construct(IConfig $config,
+ IUserManager $userManager,
+ IGroupManager $groupManager,
+ IUserSession $userSession,
+ IUserStatusManager $userStatusManager) {
$this->config = $config;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->userManager = $userManager;
+ $this->userStatusManager = $userStatusManager;
$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
@@ -99,10 +116,26 @@ class UserPlugin implements ISearchPlugin {
$foundUserById = false;
$lowerSearch = strtolower($search);
+ $userStatuses = $this->userStatusManager->getUserStatuses(array_keys($users));
foreach ($users as $uid => $user) {
$userDisplayName = $user->getDisplayName();
$userEmail = $user->getEMailAddress();
$uid = (string) $uid;
+
+ $status = [];
+ if (array_key_exists($uid, $userStatuses)) {
+ $userStatus = $userStatuses[$uid];
+ $status = [
+ 'status' => $userStatus->getStatus(),
+ 'message' => $userStatus->getMessage(),
+ 'icon' => $userStatus->getIcon(),
+ 'clearAt' => $userStatus->getClearAt()
+ ? (int)$userStatus->getClearAt()->format('U')
+ : null,
+ ];
+ }
+
+
if (
strtolower($uid) === $lowerSearch ||
strtolower($userDisplayName) === $lowerSearch ||
@@ -117,6 +150,7 @@ class UserPlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
+ 'status' => $status,
];
} else {
$addToWideResults = false;
@@ -138,6 +172,7 @@ class UserPlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
+ 'status' => $status,
];
}
}
@@ -157,12 +192,26 @@ class UserPlugin implements ISearchPlugin {
}
if ($addUser) {
+ $status = [];
+ if (array_key_exists($user->getUID(), $userStatuses)) {
+ $userStatus = $userStatuses[$user->getUID()];
+ $status = [
+ 'status' => $userStatus->getStatus(),
+ 'message' => $userStatus->getMessage(),
+ 'icon' => $userStatus->getIcon(),
+ 'clearAt' => $userStatus->getClearAt()
+ ? (int)$userStatus->getClearAt()->format('U')
+ : null,
+ ];
+ }
+
$result['exact'][] = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $user->getUID(),
],
+ 'status' => $status,
];
}
}