Node.js based forum software built for the modern web
add new hook `filter:unread.categories`
Barış Soner Uşaklı1d5816b00ac0
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.jsindex 01d5659c02..7668493337 100644--- a/src/controllers/helpers.js+++ b/src/controllers/helpers.js@@ -244,6 +244,9 @@ helpers.getWatchedCategories = function (uid, selectedCid, callback) {function (next) {user.getWatchedCategories(uid, next);},+ function (cids, next) {+ privileges.categories.filterCids('read', cids, uid, next);+ },function (cids, next) {getCategoryData(cids, uid, selectedCid, next);},@@ -256,9 +259,6 @@ function getCategoryData(cids, uid, selectedCid, callback) {}async.waterfall([function (next) {- privileges.categories.filterCids('read', cids, uid, next);- },- function (cids, next) {categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid', 'image', 'imageClass'], next);},function (categoryData, next) {@@ -302,8 +302,9 @@ function getCategoryData(cids, uid, selectedCid, callback) {function recursive(category, categoriesData, level) {category.level = level;categoriesData.push(category);-- category.children.forEach(function (child) {- recursive(child, categoriesData, ' ' + level);- });+ if (Array.isArray(category.children)) {+ category.children.forEach(function (child) {+ recursive(child, categoriesData, ' ' + level);+ });+ }}diff --git a/src/controllers/unread.js b/src/controllers/unread.jsindex 96dc4f66ce..3c2259bb4f 100644--- a/src/controllers/unread.js+++ b/src/controllers/unread.js@@ -32,7 +32,11 @@ unreadController.get = function (req, res, next) {async.parallel({watchedCategories: function (next) {- helpers.getWatchedCategories(req.uid, cid, next);+ if (plugins.hasListeners('filter:unread.categories')) {+ plugins.fireHook('filter:unread.categories', { uid: req.uid, cid: cid }, next);+ } else {+ helpers.getWatchedCategories(req.uid, cid, next);+ }},settings: function (next) {user.getSettings(req.uid, next);