diff options
author | Joas Schilling <coding@schilljs.com> | 2020-01-28 12:27:47 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-03-10 19:36:56 +0100 |
commit | bbef026aa075f4432210fcc8f089283f56f2bf72 (patch) | |
tree | a40fe948a9f06d8d74bdd1bc827b5e9a09b977a0 | |
parent | 812f16880b2cf5968a351e2f9928299458ce7b3d (diff) | |
download | nextcloud-server-bbef026aa075f4432210fcc8f089283f56f2bf72.tar.gz nextcloud-server-bbef026aa075f4432210fcc8f089283f56f2bf72.zip |
Use contacts name on federated activities
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/files/lib/Activity/Provider.php | 46 | ||||
-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 |
4 files changed, 84 insertions, 38 deletions
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index 07bc471281c..56d9f750fdf 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -28,6 +28,7 @@ use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; use OCP\Activity\IProvider; +use OCP\Contacts\IManager as IContactsManager; use OCP\Files\Folder; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; @@ -64,25 +65,27 @@ class Provider implements IProvider { /** @var IEventMerger */ protected $eventMerger; + /** @var IContactsManager */ + protected $contactsManager; + /** @var string[] cached displayNames - key is the UID and value the displayname */ protected $displayNames = []; protected $fileIsEncrypted = false; - /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - * @param IUserManager $userManager - * @param IRootFolder $rootFolder - * @param IEventMerger $eventMerger - */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IRootFolder $rootFolder, IEventMerger $eventMerger) { + public function __construct(IFactory $languageFactory, + IURLGenerator $url, + IManager $activityManager, + IUserManager $userManager, + IRootFolder $rootFolder, + IContactsManager $contactsManager, + IEventMerger $eventMerger) { $this->languageFactory = $languageFactory; $this->url = $url; $this->activityManager = $activityManager; $this->userManager = $userManager; $this->rootFolder = $rootFolder; + $this->contactsManager = $contactsManager; $this->eventMerger = $eventMerger; } @@ -499,8 +502,29 @@ class Provider implements IProvider { $user = $this->userManager->get($uid); if ($user instanceof IUser) { return $user->getDisplayName(); - } else { - return $uid; } + + $addressBookContacts = $this->contactsManager->search($uid, ['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($uid); + foreach ($cloudIds as $cloudId) { + if (strtolower($cloudId) === $lowerSearch) { + return $contact['FN'] . " ($cloudId)"; + } + } + } + } + + return $uid; } } 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(), ]; } |