diff options
author | Joas Schilling <coding@schilljs.com> | 2020-01-28 14:27:47 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-03-10 21:36:56 +0300 |
commit | bbef026aa075f4432210fcc8f089283f56f2bf72 (patch) | |
tree | a40fe948a9f06d8d74bdd1bc827b5e9a09b977a0 /apps/files_sharing/lib | |
parent | 812f16880b2cf5968a351e2f9928299458ce7b3d (diff) |
Use contacts name on federated activities
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Activity/Providers/Base.php | 46 | ||||
-rw-r--r-- | apps/files_sharing/lib/Activity/Providers/Groups.php | 17 | ||||
-rw-r--r-- | apps/files_sharing/lib/Activity/Providers/RemoteShares.php | 13 |
3 files changed, 49 insertions, 27 deletions
diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php index 237e4c5f377..77ebfc26447 100644 --- a/apps/files_sharing/lib/Activity/Providers/Base.php +++ b/apps/files_sharing/lib/Activity/Providers/Base.php @@ -26,6 +26,7 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; use OCP\Activity\IManager; use OCP\Activity\IProvider; +use OCP\Contacts\IManager as IContactsManager; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -49,20 +50,22 @@ abstract class Base implements IProvider { /** @var IUserManager */ protected $userManager; + /** @var IContactsManager */ + protected $contactsManager; + /** @var array */ protected $displayNames = []; - /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - * @param IUserManager $userManager - */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { + public function __construct(IFactory $languageFactory, + IURLGenerator $url, + IManager $activityManager, + IUserManager $userManager, + IContactsManager $contactsManager) { $this->languageFactory = $languageFactory; $this->url = $url; $this->activityManager = $activityManager; $this->userManager = $userManager; + $this->contactsManager = $contactsManager; } /** @@ -179,8 +182,33 @@ abstract class Base implements IProvider { $user = $this->userManager->get($uid); if ($user instanceof IUser) { return $user->getDisplayName(); - } else { - return $uid; } + + return $this->getDisplayNameForContact($uid); + } + + protected function getDisplayNameForContact(string $search): string { + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); + foreach ($addressBookContacts as $contact) { + if (isset($contact['isLocalSystemBook'])) { + continue; + } + + if (isset($contact['CLOUD'])) { + $cloudIds = $contact['CLOUD']; + if (is_string($cloudIds)) { + $cloudIds = [$cloudIds]; + } + + $lowerSearch = strtolower($search); + foreach ($cloudIds as $cloudId) { + if (strtolower($cloudId) === $lowerSearch) { + return $contact['FN'] . " ($cloudId)"; + } + } + } + } + + return $search; } } diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php index 184e4a5b70d..35fd03e0caa 100644 --- a/apps/files_sharing/lib/Activity/Providers/Groups.php +++ b/apps/files_sharing/lib/Activity/Providers/Groups.php @@ -26,6 +26,7 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; use OCP\Activity\IManager; +use OCP\Contacts\IManager as IContactsManager; use OCP\IGroup; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -48,15 +49,13 @@ class Groups extends Base { /** @var string[] */ protected $groupDisplayNames = []; - /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - * @param IUserManager $userManager - * @param IGroupManager $groupManager - */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager) { - parent::__construct($languageFactory, $url, $activityManager, $userManager); + public function __construct(IFactory $languageFactory, + IURLGenerator $url, + IManager $activityManager, + IUserManager $userManager, + IContactsManager $contactsManager, + IGroupManager $groupManager) { + parent::__construct($languageFactory, $url, $activityManager, $userManager, $contactsManager); $this->groupManager = $groupManager; } diff --git a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php index 2bdf36f7eea..28c62845f81 100644 --- a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php +++ b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php @@ -26,6 +26,7 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; use OCP\Activity\IManager; +use OCP\Contacts\IManager as IContactsManager; use OCP\Federation\ICloudIdManager; use OCP\IURLGenerator; use OCP\IUserManager; @@ -40,20 +41,14 @@ class RemoteShares extends Base { const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; - /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - * @param IUserManager $userManager - * @param ICloudIdManager $cloudIdManager - */ public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, + IContactsManager $contactsManager, ICloudIdManager $cloudIdManager ) { - parent::__construct($languageFactory, $url, $activityManager, $userManager); + parent::__construct($languageFactory, $url, $activityManager, $userManager, $contactsManager); $this->cloudIdManager = $cloudIdManager; } @@ -153,7 +148,7 @@ class RemoteShares extends Base { return [ 'type' => 'user', 'id' => $remoteUser->getUser(), - 'name' => $cloudId,// Todo display name from contacts + 'name' => $this->getDisplayNameForContact($remoteUser->getDisplayId()), 'server' => $remoteUser->getRemote(), ]; } |