From 1d5816b00ac0574f3f4465f6462a78b056a146f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 27 Nov 2018 13:56:09 -0500 Subject: [PATCH] add new hook `filter:unread.categories` --- src/controllers/helpers.js | 15 ++++++++------- src/controllers/unread.js | 6 +++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 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.js index 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);