From 4cb58d976b5fee5ce0888205b8124330b5b28368 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 12 Mar 2015 11:03:10 -0400 Subject: [PATCH] fix indices, main post always 0 --- src/topics.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/topics.js b/src/topics.js index 8f8915ab69..aecdcb1000 100644 --- a/src/topics.js +++ b/src/topics.js @@ -260,12 +260,20 @@ var async = require('async'), posts.getPostsByPids(pids, uid, next); }, function(posts, next) { + if (!posts.length) { + return next(null, []); + } + + if (topic.mainPid) { + posts[0].index = 0; + } + var indices = Topics.calculatePostIndices(start, end, topic.postcount, reverse); - posts.forEach(function(post, index) { - if (post) { - post.index = indices[index] - 1; + for (var i=1; i