|
|
|
@ -107,7 +107,7 @@ var async = require('async'),
|
|
|
|
|
Topics.getCategoryData = function(tid, callback) {
|
|
|
|
|
Topics.getTopicField(tid, 'cid', function(err, cid) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.getCategoryData(cid, callback);
|
|
|
|
@ -144,7 +144,13 @@ var async = require('async'),
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsData(tids, function(err, topics) {
|
|
|
|
|
var uids, cids, topics;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
Topics.getTopicsData(tids, next);
|
|
|
|
|
},
|
|
|
|
|
function(_topics, next) {
|
|
|
|
|
function mapFilter(array, field) {
|
|
|
|
|
return array.map(function(topic) {
|
|
|
|
|
return topic && topic[field] && topic[field].toString();
|
|
|
|
@ -153,17 +159,11 @@ var async = require('async'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var uids = mapFilter(topics, 'uid');
|
|
|
|
|
var cids = mapFilter(topics, 'cid');
|
|
|
|
|
topics = _topics;
|
|
|
|
|
uids = mapFilter(topics, 'uid');
|
|
|
|
|
cids = mapFilter(topics, 'cid');
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
teasers: function(next) {
|
|
|
|
|
Topics.getTeasers(topics, next);
|
|
|
|
|
},
|
|
|
|
|
users: function(next) {
|
|
|
|
|
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
|
|
|
|
},
|
|
|
|
@ -173,14 +173,15 @@ var async = require('async'),
|
|
|
|
|
hasRead: function(next) {
|
|
|
|
|
Topics.hasReadTopics(tids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
teasers: function(next) {
|
|
|
|
|
Topics.getTeasers(topics, next);
|
|
|
|
|
},
|
|
|
|
|
tags: function(next) {
|
|
|
|
|
Topics.getTopicsTagsObjects(tids, next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(results, next) {
|
|
|
|
|
var users = _.object(uids, results.users);
|
|
|
|
|
var categories = _.object(cids, results.categories);
|
|
|
|
|
|
|
|
|
@ -204,17 +205,24 @@ var async = require('async'),
|
|
|
|
|
return topic && topic.category && !topic.category.disabled;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:topics.get', {topics: topics, uid: uid}, function(err, topicData) {
|
|
|
|
|
callback(err, topicData.topics);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
plugins.fireHook('filter:topics.get', {topics: topics, uid: uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function(data, next) {
|
|
|
|
|
next(null, data.topics);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopicWithPosts = function(tid, set, uid, start, stop, reverse, callback) {
|
|
|
|
|
Topics.getTopicData(tid, function(err, topicData) {
|
|
|
|
|
if (err || !topicData) {
|
|
|
|
|
return callback(err || new Error('[[error:no-topic]]'));
|
|
|
|
|
var topicData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
Topics.getTopicData(tid, next);
|
|
|
|
|
},
|
|
|
|
|
function(_topicData, next) {
|
|
|
|
|
topicData = _topicData;
|
|
|
|
|
if (!topicData) {
|
|
|
|
|
return callback(new Error('[[error:no-topic]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
@ -224,11 +232,9 @@ var async = require('async'),
|
|
|
|
|
tags: async.apply(Topics.getTopicTagsObjects, tid),
|
|
|
|
|
isFollowing: async.apply(Topics.isFollowing, [tid], uid),
|
|
|
|
|
bookmark: async.apply(Topics.getUserBookmark, tid, uid)
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(results, next) {
|
|
|
|
|
topicData.posts = results.posts;
|
|
|
|
|
topicData.category = results.category;
|
|
|
|
|
topicData.thread_tools = results.threadTools.tools;
|
|
|
|
@ -241,11 +247,12 @@ var async = require('async'),
|
|
|
|
|
topicData.locked = parseInt(topicData.locked, 10) === 1;
|
|
|
|
|
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, function(err, data) {
|
|
|
|
|
callback(err, data ? data.topic : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, next);
|
|
|
|
|
},
|
|
|
|
|
function(data, next) {
|
|
|
|
|
next(null, data.topic);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) {
|
|
|
|
|