Skip to content

Node.js based forum software built for the modern web

Add unread-class to category children (#6071)

aStonedPenguin610a1c943fa8
diff --git a/src/categories.js b/src/categories.js
index 1487b543e2..6013091050 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -153,10 +153,10 @@ Categories.getCategories = function (cids, uid, callback) {
uid = parseInt(uid, 10);
results.categories.forEach(function (category, i) {
if (category) {
- category['unread-class'] = (parseInt(category.topic_count, 10) === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread';
category.children = results.children[i];
category.parent = results.parents[i] || undefined;
category.tagWhitelist = results.tagWhitelist[i];
+ category['unread-class'] = (parseInt(category.topic_count, 10) === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread';
calculateTopicPostCount(category);
}
});
@@ -259,9 +259,25 @@ function getChildrenRecursive(category, uid, callback) {
}
Categories.getCategoriesData(children, next);
},
- function (childrenData, next) {
- childrenData = childrenData.filter(Boolean);
- category.children = childrenData;
+ function (children, next) {
+ children = children.filter(Boolean);
+ category.children = children;
+
+ var cids = children.map(function (child) {
+ return child.cid;
+ });
+
+ Categories.hasReadCategories(cids, uid, next);
+ },
+ function (hasRead, next) {
+ hasRead.forEach(function (read, i) {
+ var child = category.children[i];
+ child['unread-class'] = (parseInt(child.topic_count, 10) === 0 || (read && uid !== 0)) ? '' : 'unread';
+ });
+
+ next();
+ },
+ function (next) {
async.each(category.children, function (child, next) {
getChildrenRecursive(child, uid, next);
}, next);