v1.18.x
barisusakli 10 years ago
parent 5f9eafcccb
commit fb6abd32c4

@ -86,8 +86,7 @@ topicsController.get = function(req, res, callback) {
set = 'tid:' + tid + ':posts:votes'; set = 'tid:' + tid + ':posts:votes';
} }
var postIndex = 0, var postIndex = 0;
index = 0;
req.params.post_index = parseInt(req.params.post_index, 10) || 0; req.params.post_index = parseInt(req.params.post_index, 10) || 0;
if (reverse && req.params.post_index === 1) { 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)); postIndex = Math.max(0, (req.params.post_index || 1) - Math.ceil(settings.postsPerPage / 2));
} }
} else if (!req.query.page) { } else if (!req.query.page) {
var index;
if (reverse) { if (reverse) {
index = Math.max(0, postCount - (req.params.post_index || postCount)); index = Math.max(0, postCount - (req.params.post_index || postCount));
} else { } else {
@ -123,7 +123,6 @@ topicsController.get = function(req, res, callback) {
topicData.pageCount = pageCount; topicData.pageCount = pageCount;
topicData.currentPage = page; topicData.currentPage = page;
topicData.postIndex = postIndex || index || req.params.post_index;
if (page > 1) { if (page > 1) {
topicData.posts.splice(0, 1); topicData.posts.splice(0, 1);
@ -153,11 +152,18 @@ topicsController.get = function(req, res, callback) {
}); });
}, },
function (topicData, next) { function (topicData, next) {
var description = '', function findPost(index) {
idx = topicData.postIndex; for(var i=0; i<topicData.posts.length; ++i) {
if (parseInt(topicData.posts[i].index, 10) === parseInt(index, 10)) {
return topicData.posts[i];
}
}
}
var description = '';
var postAtIndex = findPost(Math.max(0, req.params.post_index - 1));
if (topicData.posts[idx] && topicData.posts[idx].content) { if (postAtIndex && postAtIndex.content) {
description = S(topicData.posts[idx].content).stripTags().decodeHTMLEntities().s; description = S(postAtIndex.content).stripTags().decodeHTMLEntities().s;
} }
if (description.length > 255) { if (description.length > 255) {
@ -170,9 +176,9 @@ topicsController.get = function(req, res, callback) {
var ogImageUrl = ''; var ogImageUrl = '';
if (topicData.thumb) { if (topicData.thumb) {
ogImageUrl = topicData.thumb; ogImageUrl = topicData.thumb;
} else if(topicData.posts.length && topicData.posts[idx] && topicData.posts[idx].user && topicData.posts[idx].user.picture){ } else if (postAtIndex && postAtIndex.user && postAtIndex.user.picture){
ogImageUrl = topicData.posts[idx].user.picture; ogImageUrl = postAtIndex.user.picture;
} else if(meta.config['brand:logo']) { } else if (meta.config['brand:logo']) {
ogImageUrl = meta.config['brand:logo']; ogImageUrl = meta.config['brand:logo'];
} else { } else {
ogImageUrl = '/logo.png'; ogImageUrl = '/logo.png';

Loading…
Cancel
Save