diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 4688ce6723..be1359af08 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -86,8 +86,7 @@ topicsController.get = function(req, res, callback) { set = 'tid:' + tid + ':posts:votes'; } - var postIndex = 0, - index = 0; + var postIndex = 0; req.params.post_index = parseInt(req.params.post_index, 10) || 0; if (reverse && req.params.post_index === 1) { @@ -100,6 +99,7 @@ topicsController.get = function(req, res, callback) { postIndex = Math.max(0, (req.params.post_index || 1) - Math.ceil(settings.postsPerPage / 2)); } } else if (!req.query.page) { + var index; if (reverse) { index = Math.max(0, postCount - (req.params.post_index || postCount)); } else { @@ -123,7 +123,6 @@ topicsController.get = function(req, res, callback) { topicData.pageCount = pageCount; topicData.currentPage = page; - topicData.postIndex = postIndex || index || req.params.post_index; if (page > 1) { topicData.posts.splice(0, 1); @@ -153,11 +152,18 @@ topicsController.get = function(req, res, callback) { }); }, function (topicData, next) { - var description = '', - idx = topicData.postIndex; + function findPost(index) { + for(var i=0; i 255) { @@ -170,9 +176,9 @@ topicsController.get = function(req, res, callback) { var ogImageUrl = ''; if (topicData.thumb) { ogImageUrl = topicData.thumb; - } else if(topicData.posts.length && topicData.posts[idx] && topicData.posts[idx].user && topicData.posts[idx].user.picture){ - ogImageUrl = topicData.posts[idx].user.picture; - } else if(meta.config['brand:logo']) { + } else if (postAtIndex && postAtIndex.user && postAtIndex.user.picture){ + ogImageUrl = postAtIndex.user.picture; + } else if (meta.config['brand:logo']) { ogImageUrl = meta.config['brand:logo']; } else { ogImageUrl = '/logo.png';