Node.js based forum software built for the modern web
pass on mainPid
barisusakli9062a8f02b9a
diff --git a/src/topics.js b/src/topics.jsindex 692088ec52..a0aeed33db 100644--- a/src/topics.js+++ b/src/topics.js@@ -216,7 +216,7 @@ var async = require('async'),async.parallel({mainPost: function(next) {- Topics.getMainPost(tid, uid, next);+ getMainPosts([topicData.mainPid], uid, next);},posts: function(next) {Topics.getTopicPosts(tid, set, start, end, uid, reverse, next);@@ -230,7 +230,7 @@ var async = require('async'),return callback(err);}- topicData.posts = results.mainPost ? [results.mainPost].concat(results.posts) : results.posts;+ topicData.posts = Array.isArray(results.mainPost) && results.mainPost.length ? [results.mainPost[0]].concat(results.posts) : results.posts;topicData.category = results.category;topicData.thread_tools = results.threadTools;topicData.tags = results.tags;@@ -262,19 +262,23 @@ var async = require('async'),return topic ? topic.mainPid : null;});- posts.getPostsByPids(mainPids, uid, function(err, postData) {- if (err) {- return callback(err);+ getMainPosts(mainPids, uid, callback);+ });+ };++ function getMainPosts(mainPids, uid, callback) {+ posts.getPostsByPids(mainPids, uid, function(err, postData) {+ if (err) {+ return callback(err);+ }+ postData.forEach(function(post) {+ if (post) {+ post.index = 0;}- postData.forEach(function(post) {- if (post) {- post.index = 0;- }- });- Topics.addPostData(postData, uid, callback);});+ Topics.addPostData(postData, uid, callback);});- };+ }Topics.getTopicField = function(tid, field, callback) {db.getObjectField('topic:' + tid, field, callback);