aboutsummaryrefslogtreecommitdiffstats
path: root/apps/sharebymail
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-11-25 11:17:06 +0100
committerJoas Schilling <coding@schilljs.com>2016-11-25 11:17:06 +0100
commit719b1905d7e9dc76d5c31d72e56834e1eaab60b8 (patch)
tree43544743d50e3461fbbd575177c4e495153c0299 /apps/sharebymail
parent5c2ec584400207308241f4e64bf1b2c563c7340a (diff)
downloadnextcloud-server-719b1905d7e9dc76d5c31d72e56834e1eaab60b8.tar.gz
nextcloud-server-719b1905d7e9dc76d5c31d72e56834e1eaab60b8.zip
Get user name from contacts if available
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/sharebymail')
-rw-r--r--apps/sharebymail/lib/Activity.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/apps/sharebymail/lib/Activity.php b/apps/sharebymail/lib/Activity.php
index d80c49fc375..c5d6632d186 100644
--- a/apps/sharebymail/lib/Activity.php
+++ b/apps/sharebymail/lib/Activity.php
@@ -24,6 +24,7 @@ namespace OCA\ShareByMail;
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;
@@ -42,10 +43,15 @@ class Activity implements IProvider {
/** @var IUserManager */
protected $userManager;
+ /** @var IContactsManager */
+ protected $contactsManager;
/** @var array */
protected $displayNames = [];
+ /** @var array */
+ protected $contactNames = [];
+
const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
@@ -54,12 +60,14 @@ class Activity implements IProvider {
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
+ * @param IContactsManager $contactsManager
*/
- public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
+ public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) {
$this->l = $l;
$this->url = $url;
$this->activityManager = $activityManager;
$this->userManager = $userManager;
+ $this->contactsManager = $contactsManager;
}
/**
@@ -191,10 +199,14 @@ class Activity implements IProvider {
* @return array
*/
protected function generateEmailParameter($email) {
+ if (!isset($this->contactNames[$email])) {
+ $this->contactNames[$email] = $this->getContactName($email);
+ }
+
return [
'type' => 'email',
'id' => $email,
- 'name' => $email, // TODO ask contacts
+ 'name' => $this->contactNames[$email],
];
}
@@ -215,6 +227,26 @@ class Activity implements IProvider {
}
/**
+ * @param string $email
+ * @return string
+ */
+ protected function getContactName($email) {
+ $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
+
+ foreach ($addressBookContacts as $contact) {
+ if (isset($contact['isLocalSystemBook'])) {
+ continue;
+ }
+
+ if (in_array($email, $contact['EMAIL'])) {
+ return $contact['FN'];
+ }
+ }
+
+ return $email;
+ }
+
+ /**
* @param string $uid
* @return string
*/