Node.js based forum software built for the modern web
async posts/topics.js
barisusaklid11bfab2759f
diff --git a/src/posts.js b/src/posts.jsindex c2e252302d..bea7b6673f 100644--- a/src/posts.js+++ b/src/posts.js@@ -35,6 +35,10 @@ var async = require('async'),};Posts.getPostsByPids = function(pids, uid, callback) {+ if (!Array.isArray(pids) || !pids.length) {+ return callback(null, []);+ }+var keys = [];for (var x=0, numPids=pids.length; x<numPids; ++x) {diff --git a/src/posts/topics.js b/src/posts/topics.jsindex 29b32edf25..a9946fdace 100644--- a/src/posts/topics.js+++ b/src/posts/topics.js@@ -7,38 +7,39 @@ var async = require('async'),module.exports = function(Posts) {Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) {- Posts.getPidsFromSet(set, start, stop, reverse, function(err, pids) {- if (err) {- return callback(err);+ async.waterfall([+ function(next) {+ Posts.getPidsFromSet(set, start, stop, reverse, next);+ },+ function(pids, next) {+ Posts.getPostsByPids(pids, uid, next);}-- if (!Array.isArray(pids) || !pids.length) {- return callback(null, []);- }-- Posts.getPostsByPids(pids, uid, callback);- });+ ], callback);};Posts.isMain = function(pid, callback) {- Posts.getPostField(pid, 'tid', function(err, tid) {- if (err) {- return callback(err);+ async.waterfall([+ function(next) {+ Posts.getPostField(pid, 'tid', next);+ },+ function(tid, next) {+ topics.getTopicField(tid, 'mainPid', next);+ },+ function(mainPid, next) {+ next(null, parseInt(pid, 10) === parseInt(mainPid, 10));}- topics.getTopicField(tid, 'mainPid', function(err, mainPid) {- callback(err, parseInt(pid, 10) === parseInt(mainPid, 10));- });- });+ ], callback);};Posts.getTopicFields = function(pid, fields, callback) {- Posts.getPostField(pid, 'tid', function(err, tid) {- if (err) {- return callback(err);+ async.waterfall([+ function(next) {+ Posts.getPostField(pid, 'tid', next);+ },+ function(tid, next) {+ topics.getTopicFields(tid, fields, next);}-- topics.getTopicFields(tid, fields, callback);- });+ ], callback);};};\ No newline at end of file