Use contacts name on federated activities
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
812f16880b
commit
bbef026aa0
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue