diff --git a/src/posts.js b/src/posts.js index e17e22f300..fd250d5b38 100644 --- a/src/posts.js +++ b/src/posts.js @@ -152,7 +152,7 @@ var db = require('./database'), }); threadTools.notifyFollowers(tid, uid); - + Posts.addUserInfoToPost(postData, function(err) { if(err) { return callback(err, null); @@ -170,20 +170,28 @@ var db = require('./database'), return callback(err); } - if (pids.length) { - plugins.fireHook('filter:post.getTopic', pids, function(err, posts) { - if (!err && posts.length > 0) { - Posts.getPostsByPids(pids, function(err, posts) { - plugins.fireHook('action:post.gotTopic', posts); - callback(posts); - }); - } else { - callback(posts); + if(!pids.length) { + return callback(null, []); + } + + plugins.fireHook('filter:post.getTopic', pids, function(err, posts) { + if(err) { + return callback(err); + } + + if(!posts.length) { + return callback(null, []); + } + + + Posts.getPostsByPids(pids, function(err, posts) { + if(err) { + return callback(err); } + plugins.fireHook('action:post.gotTopic', posts); + callback(null, posts); }); - } else { - callback([]); - } + }); }); }; diff --git a/src/topics.js b/src/topics.js index e21ac7d514..bc971b8c6a 100644 --- a/src/topics.js +++ b/src/topics.js @@ -161,9 +161,13 @@ var async = require('async'), } Topics.getTopicPosts = function(tid, start, end, current_user, callback) { - posts.getPostsByTid(tid, start, end, function(postData) { + posts.getPostsByTid(tid, start, end, function(err, postData) { + if(err) { + return callback(err); + } + if (Array.isArray(postData) && !postData.length) { - return callback([]); + return callback(null, []); } for(var i=0; i