]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use the display name for files activities again
authorJoas Schilling <coding@schilljs.com>
Tue, 22 Nov 2016 15:39:29 +0000 (16:39 +0100)
committerJoas Schilling <coding@schilljs.com>
Tue, 22 Nov 2016 15:39:29 +0000 (16:39 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/files/lib/Activity/Provider.php
apps/systemtags/lib/Activity/Provider.php

index c2e753e91654228ac1399caeaf7451c62ae3efbf..676ebfc304b23158397b36daf6d7977be4588f2f 100644 (file)
@@ -26,6 +26,8 @@ use OCP\Activity\IManager;
 use OCP\Activity\IProvider;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
 
 class Provider implements IProvider {
 
@@ -38,15 +40,20 @@ class Provider implements IProvider {
        /** @var IManager */
        protected $activityManager;
 
+       /** @var IUserManager */
+       protected $userManager;
+
        /**
         * @param IL10N $l
         * @param IURLGenerator $url
         * @param IManager $activityManager
+        * @param IUserManager $userManager
         */
-       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager) {
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
                $this->l = $l;
                $this->url = $url;
                $this->activityManager = $activityManager;
+               $this->userManager = $userManager;
        }
 
        /**
@@ -265,11 +272,28 @@ class Provider implements IProvider {
                ];
        }
 
-       protected function getRichUserParameter($parameter) {
+       protected function getRichUserParameter($uid) {
+               if (!isset($this->displayNames[$uid])) {
+                       $this->displayNames[$uid] = $this->getDisplayName($uid);
+               }
+
                return [
                        'type' => 'user',
-                       'id' => $parameter,
-                       'name' => $parameter,// FIXME Use display name
+                       'id' => $uid,
+                       'name' => $this->displayNames[$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;
+               }
+       }
 }
index 9d85300d5be66b6a44bf295348aa9ed3b0d87dc5..37ede8c3b8f50adbb13171f865b730fd77a4ceb6 100644 (file)
@@ -26,6 +26,8 @@ use OCP\Activity\IManager;
 use OCP\Activity\IProvider;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
 
 class Provider implements IProvider {
 
@@ -45,15 +47,23 @@ class Provider implements IProvider {
        /** @var IManager */
        protected $activityManager;
 
+       /** @var IUserManager */
+       protected $userManager;
+
+       /** @var string[] */
+       protected $displayNames = [];
+
        /**
         * @param IL10N $l
         * @param IURLGenerator $url
         * @param IManager $activityManager
+        * @param IUserManager $userManager
         */
-       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager) {
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
                $this->l = $l;
                $this->url = $url;
                $this->activityManager = $activityManager;
+               $this->userManager = $userManager;
        }
 
        /**
@@ -278,11 +288,15 @@ class Provider implements IProvider {
                ];
        }
 
-       protected function getUserParameter($parameter) {
+       protected function getUserParameter($uid) {
+               if (!isset($this->displayNames[$uid])) {
+                       $this->displayNames[$uid] = $this->getDisplayName($uid);
+               }
+
                return [
                        'type' => 'user',
-                       'id' => $parameter,
-                       'name' => $parameter,// FIXME Use display name
+                       'id' => $uid,
+                       'name' => $this->displayNames[$uid],
                ];
        }
 
@@ -295,4 +309,17 @@ class Provider implements IProvider {
                        return $this->l->t('%s (invisible)', $parameter['name']);
                }
        }
+
+       /**
+        * @param string $uid
+        * @return string
+        */
+       protected function getDisplayName($uid) {
+               $user = $this->userManager->get($uid);
+               if ($user instanceof IUser) {
+                       return $user->getDisplayName();
+               } else {
+                       return $uid;
+               }
+       }
 }