Fixed categories without topics not being browseable.

This commit is contained in:
flash 2025-04-24 18:40:41 +00:00
parent af476491b2
commit 5ec7dddd0e
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E

View file

@ -197,16 +197,9 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
if($this->usersCtx->hasActiveBan($this->authInfo->userInfo))
$perms = $perms->apply(fn(int $calc) => $calc & (Perm::F_CATEGORY_LIST | Perm::F_CATEGORY_VIEW));
$pagination = Pagination::fromRequest($request, $this->forum->topics->countTopics(
categoryInfo: $category,
global: true,
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false
), 20);
if(!$pagination->validOffset)
return 404;
$children = [];
$topics = [];
$pagination = null;
if($category->mayHaveChildren) {
$children = $this->forum->categories->getCategoryChildren($category, hidden: false, asTree: true);
@ -283,6 +276,13 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
}
if($category->mayHaveTopics) {
$pagination = Pagination::fromRequest($request, $this->forum->topics->countTopics(
categoryInfo: $category,
global: true,
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false
), 20);
if($pagination->validOffset) {
$topicInfos = $this->forum->topics->getTopics(
categoryInfo: $category,
global: true,
@ -318,6 +318,10 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
}
}
}
}
if(empty($children) && empty($topics))
return 404;
return Template::renderRaw('forum.forum', [
'forum_breadcrumbs' => iterator_to_array($this->forum->categories->getCategoryAncestry($category)),