Use the display name for users
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
8105ba9929
commit
cf205fcaa5
|
@ -28,6 +28,8 @@ use OCP\Comments\ICommentsManager;
|
||||||
use OCP\Comments\NotFoundException;
|
use OCP\Comments\NotFoundException;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\IUser;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class Provider implements IProvider {
|
class Provider implements IProvider {
|
||||||
|
|
||||||
|
@ -40,19 +42,27 @@ class Provider implements IProvider {
|
||||||
/** @var ICommentsManager */
|
/** @var ICommentsManager */
|
||||||
protected $commentsManager;
|
protected $commentsManager;
|
||||||
|
|
||||||
|
/** @var IUserManager */
|
||||||
|
protected $userManager;
|
||||||
|
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
protected $activityManager;
|
protected $activityManager;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $displayNames = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IL10N $l
|
* @param IL10N $l
|
||||||
* @param IURLGenerator $url
|
* @param IURLGenerator $url
|
||||||
* @param ICommentsManager $commentsManager
|
* @param ICommentsManager $commentsManager
|
||||||
|
* @param IUserManager $userManager
|
||||||
* @param IManager $activityManager
|
* @param IManager $activityManager
|
||||||
*/
|
*/
|
||||||
public function __construct(IL10N $l, IURLGenerator $url, ICommentsManager $commentsManager, IManager $activityManager) {
|
public function __construct(IL10N $l, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) {
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->commentsManager = $commentsManager;
|
$this->commentsManager = $commentsManager;
|
||||||
|
$this->userManager = $userManager;
|
||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +100,6 @@ class Provider implements IProvider {
|
||||||
* @param IEvent $event
|
* @param IEvent $event
|
||||||
* @return IEvent
|
* @return IEvent
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @since 11.0.0
|
|
||||||
*/
|
*/
|
||||||
protected function parseShortVersion(IEvent $event) {
|
protected function parseShortVersion(IEvent $event) {
|
||||||
$subjectParameters = $event->getSubjectParameters();
|
$subjectParameters = $event->getSubjectParameters();
|
||||||
|
@ -117,7 +126,6 @@ class Provider implements IProvider {
|
||||||
* @param IEvent $event
|
* @param IEvent $event
|
||||||
* @return IEvent
|
* @return IEvent
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @since 11.0.0
|
|
||||||
*/
|
*/
|
||||||
protected function parseLongVersion(IEvent $event) {
|
protected function parseLongVersion(IEvent $event) {
|
||||||
$subjectParameters = $event->getSubjectParameters();
|
$subjectParameters = $event->getSubjectParameters();
|
||||||
|
@ -148,6 +156,9 @@ class Provider implements IProvider {
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IEvent $event
|
||||||
|
*/
|
||||||
protected function parseMessage(IEvent $event) {
|
protected function parseMessage(IEvent $event) {
|
||||||
$messageParameters = $event->getMessageParameters();
|
$messageParameters = $event->getMessageParameters();
|
||||||
try {
|
try {
|
||||||
|
@ -178,6 +189,11 @@ class Provider implements IProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @param string $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function generateFileParameter($id, $path) {
|
protected function generateFileParameter($id, $path) {
|
||||||
return [
|
return [
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
|
@ -188,11 +204,32 @@ class Provider implements IProvider {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uid
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function generateUserParameter($uid) {
|
protected function generateUserParameter($uid) {
|
||||||
|
if (!isset($this->displayNames[$uid])) {
|
||||||
|
$this->displayNames[$uid] = $this->getDisplayName($uid);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'id' => $uid,
|
'id' => $uid,
|
||||||
'name' => $uid,// FIXME Use display name
|
'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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue