async posts/topics.js

v1.18.x
barisusakli 10 years ago
parent 2b90568157
commit d11bfab275

@ -35,6 +35,10 @@ var async = require('async'),
}; };
Posts.getPostsByPids = function(pids, uid, callback) { Posts.getPostsByPids = function(pids, uid, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
var keys = []; var keys = [];
for (var x=0, numPids=pids.length; x<numPids; ++x) { for (var x=0, numPids=pids.length; x<numPids; ++x) {

@ -7,38 +7,39 @@ var async = require('async'),
module.exports = function(Posts) { module.exports = function(Posts) {
Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) { Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) {
Posts.getPidsFromSet(set, start, stop, reverse, function(err, pids) { async.waterfall([
if (err) { function(next) {
return callback(err); Posts.getPidsFromSet(set, start, stop, reverse, next);
},
function(pids, next) {
Posts.getPostsByPids(pids, uid, next);
} }
], callback);
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
Posts.getPostsByPids(pids, uid, callback);
});
}; };
Posts.isMain = function(pid, callback) { Posts.isMain = function(pid, callback) {
Posts.getPostField(pid, 'tid', function(err, tid) { async.waterfall([
if (err) { function(next) {
return callback(err); 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);
callback(err, parseInt(pid, 10) === parseInt(mainPid, 10));
});
});
}; };
Posts.getTopicFields = function(pid, fields, callback) { Posts.getTopicFields = function(pid, fields, callback) {
Posts.getPostField(pid, 'tid', function(err, tid) { async.waterfall([
if (err) { function(next) {
return callback(err); Posts.getPostField(pid, 'tid', next);
},
function(tid, next) {
topics.getTopicFields(tid, fields, next);
} }
], callback);
topics.getTopicFields(tid, fields, callback);
});
}; };
}; };
Loading…
Cancel
Save