diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 0b20eb7af6..51d1706885 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -70,7 +70,7 @@ topicsController.get = function(req, res, next) { function (topicData, next) { var description = ''; - if(topicData.posts.length) { + if (topicData.posts[0] && topicData.posts[0].content) { description = S(topicData.posts[0].content).stripTags().decodeHTMLEntities().s; } @@ -83,7 +83,7 @@ topicsController.get = function(req, res, next) { var ogImageUrl = ''; if (topicData.thumb) { ogImageUrl = topicData.thumb; - } else if(topicData.posts.length && topicData.posts[0].user && topicData.posts[0].user.picture){ + } else if(topicData.posts.length && topicData.posts[0] && topicData.posts[0].user && topicData.posts[0].user.picture){ ogImageUrl = topicData.posts[0].user.picture; } else if(meta.config['brand:logo']) { ogImageUrl = meta.config['brand:logo']; diff --git a/src/posts.js b/src/posts.js index a2c691dc28..53a11e9d6b 100644 --- a/src/posts.js +++ b/src/posts.js @@ -152,7 +152,7 @@ var async = require('async'), if (!data || !Array.isArray(data.posts)) { return callback(null, []); } - + data.posts = data.posts.filter(Boolean); callback(null, data.posts); }); }); diff --git a/src/topics/posts.js b/src/topics/posts.js index 4345a177dd..98c712341a 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -44,7 +44,7 @@ module.exports = function(Topics) { Topics.addPostData = function(postData, uid, callback) { var pids = postData.map(function(post) { return post && post.pid; - }).filter(Boolean); + }); if (!Array.isArray(pids) || !pids.length) { return callback(null, []); @@ -61,7 +61,7 @@ module.exports = function(Topics) { var uids = []; for(var i=0; i