From 5b26487f142843ad99a663d1ce2223c46a9498b2 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 5 Aug 2020 10:37:20 +0200 Subject: Expose status via Collaborators API Signed-off-by: Georg Ehrke --- .../Collaboration/Collaborators/UserPlugin.php | 53 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'lib/private/Collaboration') 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, ]; } } -- cgit v1.2.3