mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
some cleanup and callbacks for post
This commit is contained in:
25
src/posts.js
25
src/posts.js
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
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(userInfo, next) {
|
function(results, next) {
|
||||||
postData.user = userInfo[0];
|
postData.user = results.userInfo[0];
|
||||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next);
|
results.topicInfo.title = validator.escape(results.topicInfo.title);
|
||||||
},
|
postData.topic = results.topicInfo;
|
||||||
function(topicData, next) {
|
|
||||||
topicData.title = validator.escape(topicData.title);
|
if (results.settings.followTopicsOnReply) {
|
||||||
postData.topic = topicData;
|
|
||||||
user.getSettings(uid, next);
|
|
||||||
},
|
|
||||||
function(settings, next) {
|
|
||||||
if (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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user