summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Base.php84
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Groups.php19
-rw-r--r--apps/files_sharing/lib/Activity/Providers/RemoteShares.php32
3 files changed, 79 insertions, 56 deletions
diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php
index 237e4c5f377..b63eb346f7c 100644
--- a/apps/files_sharing/lib/Activity/Providers/Base.php
+++ b/apps/files_sharing/lib/Activity/Providers/Base.php
@@ -26,6 +26,8 @@ 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\Federation\ICloudIdManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -49,20 +51,27 @@ abstract class Base implements IProvider {
/** @var IUserManager */
protected $userManager;
+ /** @var IContactsManager */
+ protected $contactsManager;
+
+ /** @var ICloudIdManager */
+ protected $cloudIdManager;
+
/** @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,
+ ICloudIdManager $cloudIdManager,
+ IContactsManager $contactsManager) {
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
$this->userManager = $userManager;
+ $this->cloudIdManager = $cloudIdManager;
+ $this->contactsManager = $contactsManager;
}
/**
@@ -160,27 +169,62 @@ abstract class Base implements IProvider {
* @return array
*/
protected function getUser($uid) {
- if (!isset($this->displayNames[$uid])) {
- $this->displayNames[$uid] = $this->getDisplayName($uid);
+ // First try local user
+ $user = $this->userManager->get($uid);
+ if ($user instanceof IUser) {
+ return [
+ 'type' => 'user',
+ 'id' => $user->getUID(),
+ 'name' => $user->getDisplayName(),
+ ];
+ }
+
+ // Then a contact from the addressbook
+ if ($this->cloudIdManager->isValidCloudId($uid)) {
+ $cloudId = $this->cloudIdManager->resolveCloudId($uid);
+ return [
+ 'type' => 'user',
+ 'id' => $cloudId->getUser(),
+ 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()),
+ 'server' => $cloudId->getRemote(),
+ ];
}
+ // Fallback to empty dummy data
return [
'type' => 'user',
'id' => $uid,
- 'name' => $this->displayNames[$uid],
+ 'name' => $uid,
];
}
- /**
- * @param string $uid
- * @return string
- */
- protected function getDisplayName($uid) {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- return $user->getDisplayName();
- } else {
- return $uid;
+ protected function getDisplayNameFromAddressBook(string $search): string {
+ if (isset($this->displayNames[$search])) {
+ return $this->displayNames[$search];
+ }
+
+ $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) {
+ $this->displayNames[$search] = $contact['FN'] . " ($cloudId)";
+ return $this->displayNames[$search];
+ }
+ }
+ }
}
+
+ return $search;
}
}
diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php
index 184e4a5b70d..8a061f9373d 100644
--- a/apps/files_sharing/lib/Activity/Providers/Groups.php
+++ b/apps/files_sharing/lib/Activity/Providers/Groups.php
@@ -26,6 +26,8 @@ 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\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
@@ -48,15 +50,14 @@ 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,
+ ICloudIdManager $cloudIdManager,
+ IContactsManager $contactsManager,
+ IGroupManager $groupManager) {
+ parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $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..36d4dbbb8fd 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;
@@ -33,28 +34,19 @@ use OCP\L10N\IFactory;
class RemoteShares extends Base {
- protected $cloudIdManager;
-
const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted';
const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined';
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);
- $this->cloudIdManager = $cloudIdManager;
+ parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager);
}
/**
@@ -128,7 +120,7 @@ class RemoteShares extends Base {
'id' => $parameters[1],
'name' => $parameters[1],
],
- 'user' => $this->getFederatedUser($parameters[0]),
+ 'user' => $this->getUser($parameters[0]),
];
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
case self::SUBJECT_REMOTE_SHARE_DECLINED:
@@ -138,23 +130,9 @@ class RemoteShares extends Base {
}
return [
'file' => $this->getFile($fileParameter),
- 'user' => $this->getFederatedUser($parameters[0]),
+ 'user' => $this->getUser($parameters[0]),
];
}
throw new \InvalidArgumentException();
}
-
- /**
- * @param string $cloudId
- * @return array
- */
- protected function getFederatedUser($cloudId) {
- $remoteUser = $this->cloudIdManager->resolveCloudId($cloudId);
- return [
- 'type' => 'user',
- 'id' => $remoteUser->getUser(),
- 'name' => $cloudId,// Todo display name from contacts
- 'server' => $remoteUser->getRemote(),
- ];
- }
}