Skip to content

Node.js based forum software built for the modern web

recursive #3227

barisusakli49afe544e1b5
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index c0613ab5e4..d7a2a165a0 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -93,19 +93,28 @@ module.exports = function(Categories) {
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];
- }
- });
+ var posts = [];
+ getPostsRecursive(category, posts);
- if (latestPost) {
- category.posts = [latestPost];
+ posts.sort(function(a, b) {
+ return b.timestamp - a.timestamp;
+ });
+ if (posts.length) {
+ category.posts = [posts[0]];
}
});
}
+ function getPostsRecursive(category, posts) {
+ category.posts.forEach(function(p) {
+ posts.push(p);
+ });
+
+ category.children.forEach(function(child) {
+ getPostsRecursive(child, posts);
+ });
+ }
+
function assignPostsToCategories(categories, posts) {
categories.forEach(function(category) {
category.posts = posts.filter(function(post) {