From 610a1c943fa8360caa89008588b1d50f80682fc5 Mon Sep 17 00:00:00 2001 From: aStonedPenguin Date: Thu, 16 Nov 2017 23:40:39 +0000 Subject: [PATCH] Add unread-class to category children (#6071) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add unread-class to category children * unused variables * Move child unread-class to a better place * comma? ¯\_(ツ)_/¯ * feedback --- src/categories.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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);