diff --git a/src/categories/topics.js b/src/categories/topics.js index f248ee6188..12b59263cf 100644 --- a/src/categories/topics.js +++ b/src/categories/topics.js @@ -2,48 +2,57 @@ var async = require('async'), db = require('../database'), + user = require('../user'), topics = require('../topics'), plugins = require('../plugins'); module.exports = function(Categories) { Categories.getCategoryTopics = function(data, callback) { - var tids; - async.waterfall([ - async.apply(plugins.fireHook, 'filter:category.topics.prepare', data), - function(data, next) { - Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next); + async.parallel({ + isAdmin: function(next) { + user.isAdministrator(data.uid, next); }, - function(topicIds, next) { - tids = topicIds; - topics.getTopicsByTids(tids, data.uid, next); + isModerator: function(next) { + user.isModerator(data.uid, data.cid, next); }, - function(topics, next) { - if (!Array.isArray(topics) || !topics.length) { - return next(null, { - topics: [], - nextStart: 1 - }); - } + topics: function(next) { + async.waterfall([ + function(next) { + plugins.fireHook('filter:category.topics.prepare', data, next); + }, + function(data, next) { + Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next); + }, + function(tids, next) { + topics.getTopicsByTids(tids, data.uid, next); + }, + function(topics, next) { + if (!Array.isArray(topics) || !topics.length) { + return next(null, []); + } - var indices = {}, - i = 0; - for(i=0; i