This commit is contained in:
barisusakli
2015-07-10 16:43:25 -04:00
parent 534b13e089
commit 072d287183
5 changed files with 81 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ var async = require('async'),
winston = require('winston'),
_ = require('underscore'),
meta = require('../meta'),
db = require('../database'),
posts = require('../posts'),
topics = require('../topics'),
@@ -48,7 +49,11 @@ module.exports = function(Categories) {
privileges.posts.filter('read', pids, uid, next);
},
function(pids, next) {
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
if (meta.config.teaserPost === 'first') {
getMainPosts(pids, uid, next);
} else {
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
}
},
function(posts, next) {
categoryData.forEach(function(category) {
@@ -59,10 +64,33 @@ module.exports = function(Categories) {
], callback);
};
function getMainPosts(pids, uid, callback) {
async.waterfall([
function(next) {
var keys = pids.map(function(pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, ['tid'], next);
},
function(posts, next) {
var keys = posts.map(function(post) {
return 'topic:' + post.tid;
});
db.getObjectsFields(keys, ['mainPid'], next);
},
function(topics, next) {
var mainPids = topics.map(function(topic) {
return topic.mainPid;
});
posts.getPostSummaryByPids(mainPids, uid, {stripTags: true}, next);
}
], callback);
}
function assignPostsToCategory(category, posts) {
category.posts = posts.filter(function(post) {
return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10)
|| parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10));
return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10) ||
parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10));
}).sort(function(a, b) {
return b.timestamp - a.timestamp;
}).slice(0, parseInt(category.numRecentReplies, 10));