mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
closes #3227
This commit is contained in:
@@ -56,9 +56,10 @@ module.exports = function(Categories) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
function(posts, next) {
|
function(posts, next) {
|
||||||
categoryData.forEach(function(category) {
|
assignPostsToCategories(categoryData, posts);
|
||||||
assignPostsToCategory(category, posts);
|
|
||||||
});
|
bubbleUpChildrenPosts(categoryData);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
@@ -87,13 +88,33 @@ module.exports = function(Categories) {
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function assignPostsToCategory(category, posts) {
|
function bubbleUpChildrenPosts(categoryData) {
|
||||||
|
categoryData.forEach(function(category) {
|
||||||
|
if (category.posts.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var latestPost;
|
||||||
|
category.children.forEach(function(children) {
|
||||||
|
if (children.posts.length && (!latestPost || (latestPost && latestPost.timestamp < children.posts[0].timestamp))) {
|
||||||
|
latestPost = children.posts[0];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (latestPost) {
|
||||||
|
category.posts = [latestPost];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function assignPostsToCategories(categories, posts) {
|
||||||
|
categories.forEach(function(category) {
|
||||||
category.posts = posts.filter(function(post) {
|
category.posts = posts.filter(function(post) {
|
||||||
return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10) ||
|
return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10) ||
|
||||||
parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10));
|
parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10));
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a, b) {
|
||||||
return b.timestamp - a.timestamp;
|
return b.timestamp - a.timestamp;
|
||||||
}).slice(0, parseInt(category.numRecentReplies, 10));
|
}).slice(0, parseInt(category.numRecentReplies, 10));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRecentTopicPids(category, callback) {
|
function getRecentTopicPids(category, callback) {
|
||||||
|
|||||||
@@ -191,7 +191,9 @@ categoriesController.get = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(categoryData, next) {
|
function(categoryData, next) {
|
||||||
categories.getRecentTopicReplies(categoryData.children, req.uid, function(err) {
|
var allCategories = [];
|
||||||
|
categories.flattenCategories(allCategories, [categoryData]);
|
||||||
|
categories.getRecentTopicReplies(allCategories, req.uid, function(err) {
|
||||||
next(err, categoryData);
|
next(err, categoryData);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user