diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 2f50cc2bb8..8103668fdf 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -16,23 +16,18 @@ module.exports = function(Categories) { if(!parseInt(count, 10)) { return callback(null, []); } - privileges.categories.can('read', cid, uid, function(err, canRead) { - if (err || !canRead) { + + db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) { + if (err || !Array.isArray(pids) || !pids.length) { return callback(err, []); } - db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) { - if (err || !Array.isArray(pids) || !pids.length) { - return callback(err, []); + async.waterfall([ + async.apply(privileges.posts.filter, 'read', pids, uid), + function(pids, next) { + posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next); } - - async.waterfall([ - async.apply(privileges.posts.filter, 'read', pids, uid), - function(pids, next) { - posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next); - } - ], callback); - }); + ], callback); }); }; diff --git a/src/topics.js b/src/topics.js index 630425fe25..cbdac6bed2 100644 --- a/src/topics.js +++ b/src/topics.js @@ -318,6 +318,9 @@ var async = require('async'), }; Topics.getTopicsFields = function(tids, fields, callback) { + if (!Array.isArray(tids) || !tids.length) { + return callback(null, []); + } var keys = tids.map(function(tid) { return 'topic:' + tid; }); diff --git a/src/topics/unread.js b/src/topics/unread.js index 26c6ff1901..d4adf2a994 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -105,7 +105,7 @@ module.exports = function(Topics) { tids = tids.slice(start, stop + 1); } - callback(err, tids); + callback(null, tids); }); }); }; @@ -115,45 +115,22 @@ module.exports = function(Topics) { return callback(null, tids); } - privileges.topics.filter('read', tids, uid, function(err, tids) { - if (err || !tids.length) { - return callback(err, []); - } - - var keys = tids.map(function(tid) { - return 'topic:' + tid; - }); - - db.getObjectsFields(keys, ['tid', 'cid'], function(err, topics) { - if (err) { - return callback(err); - } - - var topicCids = topics.filter(function(topic) { - return topic && topic.cid; + async.waterfall([ + function(next) { + privileges.topics.filter('read', tids, uid, next); + }, + function(tids, next) { + Topics.getTopicsFields(tids, ['tid', 'cid'], next); + }, + function(topics, next) { + tids = topics.filter(function(topic) { + return topic && topic.cid && ignoredCids.indexOf(topic.cid.toString()) === -1; }).map(function(topic) { - return topic.cid.toString(); - }); - - topicCids = topicCids.filter(function(cid) { - return ignoredCids.indexOf(cid) === -1; - }); - - privileges.categories.filterCids('read', topicCids, uid, function(err, readableCids) { - if (err) { - return callback(err); - } - - topics = topics.filter(function(topic) { - return topic.cid && readableCids.indexOf(topic.cid.toString()) !== -1; - }).map(function(topic) { - return topic.tid; - }); - - callback(null, topics); + return topic.tid; }); - }); - }); + next(null, tids); + } + ], callback); } Topics.pushUnreadCount = function(uid, callback) {