added err first to some calls

v1.18.x
Baris Soner Usakli 11 years ago
parent b86a01ded1
commit 1021615848

@ -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([]);
}
});
});
};

@ -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<postData.length; ++i) {
@ -176,8 +180,9 @@ var async = require('async'),
function getFavouritesData(next) {
var pids = [];
for (var i = 0; i < postData.length; ++i)
for (var i = 0; i < postData.length; ++i) {
pids.push(postData[i].pid);
}
favourites.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
next(null, fav_data);
@ -203,6 +208,10 @@ var async = require('async'),
}
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {
if(err) {
return callback(err);
}
var fav_data = results[0],
privileges = results[2];
@ -211,7 +220,7 @@ var async = require('async'),
postData[i].display_moderator_tools = ((current_user != 0) && (postData[i].uid == current_user || privileges.editable));
}
callback(postData);
callback(null, postData);
});
});
}
@ -539,9 +548,7 @@ var async = require('async'),
};
function getTopicPosts(next) {
Topics.getTopicPosts(tid, start, end, current_user, function(topicPosts) {
next(null, topicPosts);
});
Topics.getTopicPosts(tid, start, end, current_user, next);
};
function getPrivileges(next) {

@ -875,7 +875,7 @@ websockets.init = function(io) {
var start = data.after,
end = start + 9;
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
topics.getTopicPosts(data.tid, start, end, uid, function(err, posts) {
callback({
posts: posts
});

Loading…
Cancel
Save