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'),
utils = require('./../public/src/utils'),
utils = require('../public/src/utils'),
user = require('./user'),
groups = require('./groups'),
topics = require('./topics'),
@ -70,17 +70,24 @@ var async = require('async'),
db.setObject('post:' + postData.pid, postData, next);
},
function(next) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid);
db.incrObjectField('global', 'postCount');
emitter.emit('event:newpost', postData);
plugins.fireHook('filter:post.get', postData, next);
async.parallel([
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) {
postTools.parse(postData.content, function(err, content) {
if(err) {
if (err) {
return next(err);
}
@ -430,7 +437,7 @@ var async = require('async'),
var cids = posts.map(function(post) {
return map[post.tid];
})
});
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) {
uids = data.uidsTo;
for(var i=0; i<uids.length; ++i) {
if (parseInt(uids[i], 10) !== socket.uid) {
websockets.in('uid_' + uids[i]).emit('event:new_post', result);

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

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

Loading…
Cancel
Save