diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2016-10-25 16:24:24 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2016-11-01 19:54:40 +0100 |
commit | 8c8a019b7eb3de0262712aa145e5cd7e4f3cd2bd (patch) | |
tree | c43a2feb48867544b8e6fb72bb8a2e922e1f0c04 /apps/files_sharing/lib | |
parent | 60a3893ca848c862ee3e5d8d8d7eb035c8c0228b (diff) | |
download | nextcloud-server-8c8a019b7eb3de0262712aa145e5cd7e4f3cd2bd.tar.gz nextcloud-server-8c8a019b7eb3de0262712aa145e5cd7e4f3cd2bd.zip |
show correct display name if we have the user in one of our address books
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 0f4173f8763..186f314a1c8 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -23,7 +23,6 @@ */ namespace OCA\Files_Sharing\Controller; -use OC\Share20\Exception\ProviderException; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; @@ -37,7 +36,6 @@ use OCP\IL10N; use OCP\IUserManager; use OCP\IRequest; use OCP\IURLGenerator; -use OCP\IUser; use OCP\Files\IRootFolder; use OCP\Lock\LockedException; use OCP\Share\IManager; @@ -187,11 +185,11 @@ class ShareAPIController extends OCSController { } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { $result['share_with'] = $share->getSharedWith(); - $result['share_with_displayname'] = $share->getSharedWith(); + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); $result['token'] = $share->getToken(); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { $result['share_with'] = $share->getSharedWith(); - $result['share_with_displayname'] = $share->getSharedWith(); + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); $result['token'] = $share->getToken(); } @@ -201,6 +199,28 @@ class ShareAPIController extends OCSController { } /** + * Check if one of the users address books knows the exact property, if + * yes we return the full name. + * + * @param string $query + * @param string $property + * @return string + */ + private function getDisplayNameFromAddressBook($query, $property) { + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered + $result = \OC::$server->getContactsManager()->search($query, [$property]); + foreach ($result as $r) { + foreach($r[$property] as $value) { + if ($value === $query) { + return $r['FN']; + } + } + } + + return $query; + } + + /** * Get a specific share by id * * @NoAdminRequired |