Moved user related stuff into its own context object.
This commit is contained in:
parent
618a3c31d9
commit
ade2460b92
37 changed files with 367 additions and 624 deletions
src/Changelog
|
@ -15,31 +15,16 @@ use Misuzu\Feeds\Feed;
|
|||
use Misuzu\Feeds\FeedItem;
|
||||
use Misuzu\Feeds\AtomFeedSerializer;
|
||||
use Misuzu\Feeds\RssFeedSerializer;
|
||||
use Misuzu\Users\Users;
|
||||
use Misuzu\Users\UsersContext;
|
||||
|
||||
final class ChangelogRoutes implements IRouteHandler {
|
||||
private IConfig $config;
|
||||
private Changelog $changelog;
|
||||
private Users $users;
|
||||
private AuthInfo $authInfo;
|
||||
private Comments $comments;
|
||||
|
||||
private array $userInfos = [];
|
||||
private array $userColours = [];
|
||||
|
||||
public function __construct(
|
||||
IConfig $config,
|
||||
Changelog $changelog,
|
||||
Users $users,
|
||||
AuthInfo $authInfo,
|
||||
Comments $comments
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->changelog = $changelog;
|
||||
$this->users = $users;
|
||||
$this->authInfo = $authInfo;
|
||||
$this->comments = $comments;
|
||||
}
|
||||
private IConfig $config,
|
||||
private Changelog $changelog,
|
||||
private UsersContext $usersCtx,
|
||||
private AuthInfo $authInfo,
|
||||
private Comments $comments
|
||||
) {}
|
||||
|
||||
public function registerRoutes(IRouter $router): void {
|
||||
$router->get('/changelog', $this->getIndex(...));
|
||||
|
@ -62,7 +47,7 @@ final class ChangelogRoutes implements IRouteHandler {
|
|||
}
|
||||
|
||||
private function getCommentsInfo(string $categoryName): object {
|
||||
$comments = new CommentsEx($this->authInfo, $this->comments, $this->users, $this->userInfos, $this->userColours);
|
||||
$comments = new CommentsEx($this->authInfo, $this->comments, $this->usersCtx);
|
||||
return $comments->getCommentsForLayout($categoryName);
|
||||
}
|
||||
|
||||
|
@ -85,7 +70,7 @@ final class ChangelogRoutes implements IRouteHandler {
|
|||
$filterUser = null;
|
||||
else
|
||||
try {
|
||||
$filterUser = $this->users->getUser($filterUser, 'id');
|
||||
$filterUser = $this->usersCtx->getUserInfo($filterUser);
|
||||
} catch(RuntimeException $ex) {
|
||||
return 404;
|
||||
}
|
||||
|
@ -110,28 +95,12 @@ final class ChangelogRoutes implements IRouteHandler {
|
|||
$changes = [];
|
||||
|
||||
foreach($changeInfos as $changeInfo) {
|
||||
$userId = $changeInfo->getUserId();
|
||||
|
||||
if(array_key_exists($userId, $this->userInfos)) {
|
||||
$userInfo = $this->userInfos[$userId];
|
||||
$userColour = $this->userColours[$userId];
|
||||
} else {
|
||||
try {
|
||||
$userInfo = $this->users->getUser($userId, 'id');
|
||||
$userColour = $this->users->getUserColour($userInfo);
|
||||
} catch(RuntimeException $ex) {
|
||||
$userInfo = null;
|
||||
$userColour = null;
|
||||
}
|
||||
|
||||
$this->userInfos[$userId] = $userInfo;
|
||||
$this->userColours[$userId] = $userColour;
|
||||
}
|
||||
$userInfo = $changeInfo->hasUserId() ? $this->usersCtx->getUserInfo($changeInfo->getUserId()) : null;
|
||||
|
||||
$changes[] = [
|
||||
'change' => $changeInfo,
|
||||
'user' => $userInfo,
|
||||
'user_colour' => $userColour,
|
||||
'user_colour' => $this->usersCtx->getUserColour($userInfo),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -153,20 +122,13 @@ final class ChangelogRoutes implements IRouteHandler {
|
|||
}
|
||||
|
||||
$tagInfos = $this->changelog->getTags(changeInfo: $changeInfo);
|
||||
|
||||
try {
|
||||
$userInfo = $this->users->getUser($changeInfo->getUserId(), 'id');
|
||||
$userColour = $this->users->getUserColour($userInfo);
|
||||
} catch(RuntimeException $ex) {
|
||||
$userInfo = null;
|
||||
$userColour = null;
|
||||
}
|
||||
$userInfo = $changeInfo->hasUserId() ? $this->usersCtx->getUserInfo($changeInfo->getUserId()) : null;
|
||||
|
||||
return Template::renderRaw('changelog.change', [
|
||||
'change_info' => $changeInfo,
|
||||
'change_tags' => $tagInfos,
|
||||
'change_user_info' => $userInfo,
|
||||
'change_user_colour' => $userColour,
|
||||
'change_user_colour' => $this->usersCtx->getUserColour($userInfo),
|
||||
'comments_info' => $this->getCommentsInfo($changeInfo->getCommentsCategoryName()),
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue