use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
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;
}
/**
];
}
- 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;
+ }
+ }
}
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
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;
}
/**
];
}
- 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],
];
}
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;
+ }
+ }
}