mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
fix for null category (#7029)
This commit is contained in:
committed by
Barış Soner Uşaklı
parent
8a5a031db8
commit
dab1a1d638
@@ -85,7 +85,7 @@ module.exports = function (Categories) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
const categoriesToLoad = categoryData.filter(category => parseInt(category.numRecentReplies, 10) > 0);
|
const categoriesToLoad = categoryData.filter(category => category && category.numRecentReplies && parseInt(category.numRecentReplies, 10) > 0);
|
||||||
const keys = categoriesToLoad.map(category => 'cid:' + category.cid + ':recent_tids');
|
const keys = categoriesToLoad.map(category => 'cid:' + category.cid + ':recent_tids');
|
||||||
db.getSortedSetsMembers(keys, next);
|
db.getSortedSetsMembers(keys, next);
|
||||||
},
|
},
|
||||||
@@ -153,23 +153,27 @@ module.exports = function (Categories) {
|
|||||||
|
|
||||||
function assignTopicsToCategories(categories, topics) {
|
function assignTopicsToCategories(categories, topics) {
|
||||||
categories.forEach(function (category) {
|
categories.forEach(function (category) {
|
||||||
category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid))
|
if (category) {
|
||||||
.sort((a, b) => b.pid - a.pid)
|
category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid))
|
||||||
.slice(0, parseInt(category.numRecentReplies, 10));
|
.sort((a, b) => b.pid - a.pid)
|
||||||
|
.slice(0, parseInt(category.numRecentReplies, 10));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function bubbleUpChildrenPosts(categoryData) {
|
function bubbleUpChildrenPosts(categoryData) {
|
||||||
categoryData.forEach(function (category) {
|
categoryData.forEach(function (category) {
|
||||||
if (category.posts.length) {
|
if (category) {
|
||||||
return;
|
if (category.posts.length) {
|
||||||
}
|
return;
|
||||||
var posts = [];
|
}
|
||||||
getPostsRecursive(category, posts);
|
var posts = [];
|
||||||
|
getPostsRecursive(category, posts);
|
||||||
|
|
||||||
posts.sort((a, b) => b.pid - a.pid);
|
posts.sort((a, b) => b.pid - a.pid);
|
||||||
if (posts.length) {
|
if (posts.length) {
|
||||||
category.posts = [posts[0]];
|
category.posts = [posts[0]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user