|
|
|
@ -5,57 +5,49 @@ var async = require('async');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var topics = require('../topics');
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
var privileges = require('../privileges');
|
|
|
|
|
|
|
|
|
|
module.exports = function(Categories) {
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryTopics = function(data, callback) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdminOrMod: function(next) {
|
|
|
|
|
privileges.categories.isAdminOrMod(data.cid, data.uid, next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('filter:category.topics.prepare', data, next);
|
|
|
|
|
},
|
|
|
|
|
topics: function(next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
plugins.fireHook('filter:category.topics.prepare', data, next);
|
|
|
|
|
},
|
|
|
|
|
function(data, next) {
|
|
|
|
|
Categories.getTopicIds(data.set, data.reverse, 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, {topics: [], uid: data.uid});
|
|
|
|
|
}
|
|
|
|
|
function (data, next) {
|
|
|
|
|
Categories.getTopicIds(data.set, data.reverse, 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, {topics: [], uid: data.uid});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<topics.length; ++i) {
|
|
|
|
|
topics[i].index = data.start + i;
|
|
|
|
|
}
|
|
|
|
|
for (var i=0; i<topics.length; ++i) {
|
|
|
|
|
topics[i].index = data.start + i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:category.topics.get', {topics: topics, uid: data.uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function(results, next) {
|
|
|
|
|
next(null, results.topics);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
plugins.fireHook('filter:category.topics.get', {topics: topics, uid: data.uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
next(null, {topics: results.topics, nextStart: data.stop + 1});
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
results.topics.forEach(function(topic) {
|
|
|
|
|
if (!(!topic.deleted || results.isAdminOrMod || topic.isOwner)) {
|
|
|
|
|
topic.title = '[[topic:topic_is_deleted]]';
|
|
|
|
|
topic.slug = topic.tid;
|
|
|
|
|
topic.teaser = null;
|
|
|
|
|
topic.noAnchor = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Categories.modifyTopicsByPrivilege = function(topics, privileges) {
|
|
|
|
|
if (!Array.isArray(topics) || !topics.length || privileges.isAdminOrMod) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, {topics: results.topics, nextStart: data.stop + 1});
|
|
|
|
|
topics.forEach(function(topic) {
|
|
|
|
|
if (topic.deleted && !topic.isOwner) {
|
|
|
|
|
topic.title = '[[topic:topic_is_deleted]]';
|
|
|
|
|
topic.slug = topic.tid;
|
|
|
|
|
topic.teaser = null;
|
|
|
|
|
topic.noAnchor = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|