bubble replies from subcategories to the parents

v1.18.x
barisusakli 9 years ago
parent 42ebc15521
commit b2311edb94

@ -9,6 +9,7 @@ var _ = require('underscore');
var db = require('../database');
var posts = require('../posts');
var topics = require('../topics');
var categories = require('../categories');
var privileges = require('../privileges');
module.exports = function(Categories) {
@ -113,12 +114,26 @@ module.exports = function(Categories) {
topic.teaserPid = topic.teaserPid || topic.mainPid;
}
});
topics.getTeasers(_topicData, next);
var cids = _topicData.map(function(topic) {
return topic && topic.cid;
}).filter(function(cid, index, array) {
return cid && array.indexOf(cid) === index;
});
async.parallel({
categoryData: async.apply(categories.getCategoriesFields, cids, ['cid', 'parentCid']),
teasers: async.apply(topics.getTeasers, _topicData),
}, next);
},
function (teasers, next) {
teasers.forEach(function(teaser, index) {
function (results, next) {
var parentCids = {};
results.categoryData.forEach(function(category) {
parentCids[category.cid] = category.parentCid;
});
results.teasers.forEach(function(teaser, index) {
if (teaser) {
teaser.cid = topicData[index].cid;
teaser.parentCid = parseInt(parentCids[teaser.cid]) || 0;
teaser.tid = teaser.uid = teaser.user.uid = undefined;
teaser.topic = {
slug: topicData[index].slug,
@ -126,8 +141,8 @@ module.exports = function(Categories) {
};
}
});
teasers = teasers.filter(Boolean);
next(null, teasers);
results.teasers = results.teasers.filter(Boolean);
next(null, results.teasers);
}
], callback);
}
@ -135,7 +150,8 @@ module.exports = function(Categories) {
function assignTopicsToCategories(categories, topics) {
categories.forEach(function(category) {
category.posts = topics.filter(function(topic) {
return topic.cid && parseInt(topic.cid, 10) === parseInt(category.cid, 10);
return topic.cid && (parseInt(topic.cid, 10) === parseInt(category.cid, 10) ||
parseInt(topic.parentCid, 10) === parseInt(category.cid, 10));
}).sort(function(a, b) {
return b.pid - a.pid;
}).slice(0, parseInt(category.numRecentReplies, 10));

Loading…
Cancel
Save