Merge pull request #2246 from nextcloud/display-name-for-files-and-tagging-activities-again
Use the display name for files activities again
This commit is contained in:
commit
f4470b6861
2 changed files with 62 additions and 8 deletions
|
@ -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,23 @@ class Provider implements IProvider {
|
|||
/** @var IManager */
|
||||
protected $activityManager;
|
||||
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
|
||||
/** @var string[] cached displayNames - key is the UID and value the displayname */
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,11 +275,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue