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';
}
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<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) {
description = S(topicData.posts[idx].content).stripTags().decodeHTMLEntities().s;
if (postAtIndex && postAtIndex.content) {
description = S(postAtIndex.content).stripTags().decodeHTMLEntities().s;
}
if (description.length > 255) {
@ -170,8 +176,8 @@ 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 (postAtIndex && postAtIndex.user && postAtIndex.user.picture){
ogImageUrl = postAtIndex.user.picture;
} else if (meta.config['brand:logo']) {
ogImageUrl = meta.config['brand:logo'];
} else {

Loading…
Cancel
Save