mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
some cleanup and callbacks for post
This commit is contained in:
21
src/posts.js
21
src/posts.js
@@ -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,13 +70,20 @@ 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);
|
||||
|
||||
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) {
|
||||
@@ -430,7 +437,7 @@ var async = require('async'),
|
||||
|
||||
var cids = posts.map(function(post) {
|
||||
return map[post.tid];
|
||||
})
|
||||
});
|
||||
|
||||
callback(null, cids);
|
||||
});
|
||||
|
||||
@@ -59,17 +59,28 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetAdd('topics:tid', timestamp, 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);
|
||||
|
||||
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);
|
||||
callback(null, tid);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -166,26 +177,29 @@ module.exports = function(Topics) {
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
exists: function(next) {
|
||||
threadTools.exists(tid, next);
|
||||
},
|
||||
function(topicExists, next) {
|
||||
if (!topicExists) {
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
locked: function(next) {
|
||||
Topics.isLocked(tid, next);
|
||||
},
|
||||
function(locked, next) {
|
||||
if (locked) {
|
||||
canReply: function(next) {
|
||||
privileges.topics.can('topics:reply', tid, uid, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
if (!results.exists) {
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
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) {
|
||||
async.parallel({
|
||||
userInfo: function(next) {
|
||||
posts.getUserInfoForPosts([postData.uid], next);
|
||||
},
|
||||
function(userInfo, next) {
|
||||
postData.user = userInfo[0];
|
||||
topicInfo: function(next) {
|
||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next);
|
||||
},
|
||||
function(topicData, next) {
|
||||
topicData.title = validator.escape(topicData.title);
|
||||
postData.topic = topicData;
|
||||
settings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
function(settings, next) {
|
||||
if (settings.followTopicsOnReply) {
|
||||
postIndex: function(next) {
|
||||
posts.getPidIndex(postData.pid, uid, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user