From 1e6d5890807d35178aa06ac6a4825822a54ffaa5 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 22 Jul 2014 14:35:30 -0400 Subject: [PATCH] show topics on home instead of replies no template changes, instead of showing the latest x posts under categories, we are now showing the latest x posts of the latest x topics. --- src/categories/recentreplies.js | 22 +++++++++++++++++++++- src/controllers/index.js | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index a488937dcf..ae6f41fe4c 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -10,7 +10,7 @@ var async = require('async'), module.exports = function(Categories) { Categories.getRecentReplies = function(cid, uid, count, callback) { - if(!parseInt(count, 10)) { + if (!parseInt(count, 10)) { return callback(null, []); } @@ -23,6 +23,26 @@ module.exports = function(Categories) { }); }; + Categories.getRecentTopicReplies = function(cid, uid, count, callback) { + if (!parseInt(count, 10)) { + return callback(null, []); + } + + db.getSortedSetRevRange('categories:' + cid + ':tid', 0, count - 1, function(err, tids) { + if (err || !tids || !tids.length) { + return callback(err, []); + } + + async.map(tids, topics.getLatestUndeletedPid, function(err, pids) { + pids = pids.filter(function(pid) { + return !!pid; + }); + + posts.getPostSummaryByPids(pids, {stripTags: true}, callback); + }); + }); + }; + Categories.moveRecentReplies = function(tid, oldCid, cid) { function movePost(postData, next) { async.parallel([ diff --git a/src/controllers/index.js b/src/controllers/index.js index b8b4fc3175..81217367a0 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -70,7 +70,7 @@ Controllers.home = function(req, res, next) { } function getRecentReplies(category, callback) { - categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) { + categories.getRecentTopicReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) { if (err) { return callback(err); }