some cleanup and callbacks for post

v1.18.x
barisusakli 11 years ago
parent 2bcd43531a
commit 327d1c1bec

@ -11,7 +11,7 @@ var async = require('async'),
db = require('./database'), db = require('./database'),
utils = require('./../public/src/utils'), utils = require('../public/src/utils'),
user = require('./user'), user = require('./user'),
groups = require('./groups'), groups = require('./groups'),
topics = require('./topics'), topics = require('./topics'),
@ -70,17 +70,24 @@ var async = require('async'),
db.setObject('post:' + postData.pid, postData, next); db.setObject('post:' + postData.pid, postData, next);
}, },
function(next) { function(next) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid);
db.incrObjectField('global', 'postCount');
emitter.emit('event:newpost', postData); emitter.emit('event:newpost', postData);
async.parallel([
plugins.fireHook('filter:post.get', postData, next); function(next) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid, next);
},
function(next) {
db.incrObjectField('global', 'postCount', next);
}
], function(err) {
if (err) {
return next(err);
}
plugins.fireHook('filter:post.get', postData, next);
});
}, },
function(postData, next) { function(postData, next) {
postTools.parse(postData.content, function(err, content) { postTools.parse(postData.content, function(err, content) {
if(err) { if (err) {
return next(err); return next(err);
} }
@ -430,7 +437,7 @@ var async = require('async'),
var cids = posts.map(function(post) { var cids = posts.map(function(post) {
return map[post.tid]; return map[post.tid];
}) });
callback(null, cids); callback(null, cids);
}); });

@ -54,7 +54,7 @@ SocketPosts.reply = function(socket, data, callback) {
plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: data.uid, type: "newPost"}, function(err, data) { plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: data.uid, type: "newPost"}, function(err, data) {
uids = data.uidsTo; uids = data.uidsTo;
for(var i=0; i<uids.length; ++i) { for(var i=0; i<uids.length; ++i) {
if (parseInt(uids[i], 10) !== socket.uid) { if (parseInt(uids[i], 10) !== socket.uid) {
websockets.in('uid_' + uids[i]).emit('event:new_post', result); websockets.in('uid_' + uids[i]).emit('event:new_post', result);

@ -59,17 +59,28 @@ module.exports = function(Topics) {
return callback(err); return callback(err);
} }
db.sortedSetAdd('topics:tid', timestamp, tid); async.parallel([
plugins.fireHook('action:topic.save', tid); function(next) {
db.sortedSetsAdd(['topics:tid', 'categories:' + cid + ':tid'], timestamp, tid, next);
user.addTopicIdToUser(uid, tid, timestamp); },
function(next) {
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid); user.addTopicIdToUser(uid, tid, timestamp, next);
db.incrObjectField('category:' + cid, 'topic_count'); },
db.incrObjectField('global', 'topicCount'); function(next) {
db.incrObjectField('category:' + cid, 'topic_count', next);
Topics.createTags(data.tags, tid, timestamp, function(err) { },
callback(err, tid); function(next) {
db.incrObjectField('global', 'topicCount', next);
},
function(next) {
Topics.createTags(data.tags, tid, timestamp, next);
}
], function(err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:topic.save', tid);
callback(null, tid);
}); });
}); });
}); });
@ -166,26 +177,29 @@ module.exports = function(Topics) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
threadTools.exists(tid, next); async.parallel({
exists: function(next) {
threadTools.exists(tid, next);
},
locked: function(next) {
Topics.isLocked(tid, next);
},
canReply: function(next) {
privileges.topics.can('topics:reply', tid, uid, next);
}
}, next);
}, },
function(topicExists, next) { function(results, next) {
if (!topicExists) { if (!results.exists) {
return next(new Error('[[error:no-topic]]')); return next(new Error('[[error:no-topic]]'));
} }
if (results.locked) {
Topics.isLocked(tid, next);
},
function(locked, next) {
if (locked) {
return next(new Error('[[error:topic-locked]]')); return next(new Error('[[error:topic-locked]]'));
} }
if (!results.canReply) {
privileges.topics.can('topics:reply', tid, uid, next);
},
function(canReply, next) {
if (!canReply) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
user.isReadyToPost(uid, next); user.isReadyToPost(uid, next);
}, },
function(next) { function(next) {
@ -211,25 +225,30 @@ module.exports = function(Topics) {
Topics.markAsRead([tid], uid, next); Topics.markAsRead([tid], uid, next);
}, },
function(next) { function(next) {
posts.getUserInfoForPosts([postData.uid], next); async.parallel({
}, userInfo: function(next) {
function(userInfo, next) { posts.getUserInfoForPosts([postData.uid], next);
postData.user = userInfo[0]; },
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next); topicInfo: function(next) {
}, Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next);
function(topicData, next) { },
topicData.title = validator.escape(topicData.title); settings: function(next) {
postData.topic = topicData; user.getSettings(uid, next);
user.getSettings(uid, next); },
postIndex: function(next) {
posts.getPidIndex(postData.pid, uid, next);
}
}, next);
}, },
function(settings, next) { function(results, next) {
if (settings.followTopicsOnReply) { postData.user = results.userInfo[0];
results.topicInfo.title = validator.escape(results.topicInfo.title);
postData.topic = results.topicInfo;
if (results.settings.followTopicsOnReply) {
threadTools.follow(postData.tid, uid); threadTools.follow(postData.tid, uid);
} }
posts.getPidIndex(postData.pid, uid, next); postData.index = results.postIndex - 1;
},
function(index, next) {
postData.index = index - 1;
postData.favourited = false; postData.favourited = false;
postData.votes = 0; postData.votes = 0;
postData.display_moderator_tools = true; postData.display_moderator_tools = true;

@ -318,12 +318,12 @@ var
}); });
}; };
User.addPostIdToUser = function(uid, pid, timestamp) { User.addPostIdToUser = function(uid, pid, timestamp, callback) {
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid); db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid, callback);
}; };
User.addTopicIdToUser = function(uid, tid, timestamp) { User.addTopicIdToUser = function(uid, tid, timestamp, callback) {
db.sortedSetAdd('uid:' + uid + ':topics', timestamp, tid); db.sortedSetAdd('uid:' + uid + ':topics', timestamp, tid, callback);
}; };
User.getPostIds = function(uid, start, stop, callback) { User.getPostIds = function(uid, start, stop, callback) {

Loading…
Cancel
Save