mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	wait for callback
This commit is contained in:
		| @@ -9,7 +9,6 @@ var db = require('./database'), | ||||
| 	topics = require('./topics'), | ||||
| 	plugins = require('./plugins'), | ||||
| 	meta = require('./meta'), | ||||
| 	emitter = require('./emitter'), | ||||
| 	validator = require('validator'), | ||||
| 	privileges = require('./privileges'), | ||||
|  | ||||
| @@ -418,27 +417,35 @@ var db = require('./database'), | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	Categories.onNewPostMade = function(postData) { | ||||
| 	Categories.onNewPostMade = function(postData, callback) { | ||||
| 		topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) { | ||||
| 			if (err) { | ||||
| 				return winston.error(err.message); | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			if (!topicData) { | ||||
| 				return; | ||||
| 				return callback(); | ||||
| 			} | ||||
|  | ||||
| 			var cid = topicData.cid; | ||||
|  | ||||
| 			db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid); | ||||
| 			db.incrObjectField('category:' + cid, 'post_count'); | ||||
|  | ||||
| 			async.parallel([ | ||||
| 				function(next) { | ||||
| 					db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next); | ||||
| 				}, | ||||
| 				function(next) { | ||||
| 					db.incrObjectField('category:' + cid, 'post_count', next); | ||||
| 				}, | ||||
| 				function(next) { | ||||
| 					if(parseInt(topicData.pinned, 10) === 0) { | ||||
| 				db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid); | ||||
| 						db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid, next); | ||||
| 					} else { | ||||
| 						next(); | ||||
| 					} | ||||
| 				} | ||||
| 			], callback); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| 	emitter.on('event:newpost', Categories.onNewPostMade); | ||||
|  | ||||
| }(exports)); | ||||
|   | ||||
| @@ -211,7 +211,7 @@ var winston = require('winston'), | ||||
| 				} | ||||
|  | ||||
| 				if (timestamp) { | ||||
| 					topics.updateTimestamp(tid, timestamp); | ||||
| 					return topics.updateTimestamp(tid, timestamp, callback); | ||||
| 				} | ||||
| 				callback(); | ||||
| 			}); | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/posts.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/posts.js
									
									
									
									
									
								
							| @@ -70,8 +70,16 @@ var async = require('async'), | ||||
| 				db.setObject('post:' + postData.pid, postData, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				emitter.emit('event:newpost', postData); | ||||
| 				async.parallel([ | ||||
| 					function(next) { | ||||
| 						user.onNewPostMade(postData, next); | ||||
| 					}, | ||||
| 					function(next) { | ||||
| 						topics.onNewPostMade(postData, next); | ||||
| 					}, | ||||
| 					function(next) { | ||||
| 						categories.onNewPostMade(postData, next); | ||||
| 					}, | ||||
| 					function(next) { | ||||
| 						db.sortedSetAdd('posts:pid', timestamp, postData.pid, next); | ||||
| 					}, | ||||
|   | ||||
| @@ -48,9 +48,13 @@ module.exports = function(Topics) { | ||||
| 						return callback(err); | ||||
| 					} | ||||
|  | ||||
| 					Topics.updateTimestamp(tid, Date.now()); | ||||
| 					Topics.updateTimestamp(tid, Date.now(), function(err) { | ||||
| 						if (err) { | ||||
| 							return callback(err); | ||||
| 						} | ||||
| 						Topics.getTopicData(tid, callback); | ||||
| 					}); | ||||
| 				}); | ||||
|  | ||||
| 				function move(pid, next) { | ||||
| 					privileges.posts.canEdit(pid, uid, function(err, canEdit) { | ||||
|   | ||||
| @@ -7,20 +7,26 @@ var async = require('async'), | ||||
|  | ||||
| 	db = require('../database'), | ||||
| 	user = require('../user'), | ||||
| 	emitter = require('../emitter'), | ||||
| 	favourites = require('../favourites'), | ||||
| 	posts = require('../posts'), | ||||
| 	privileges = require('../privileges'); | ||||
|  | ||||
| module.exports = function(Topics) { | ||||
|  | ||||
| 	Topics.onNewPostMade = function(postData) { | ||||
| 		Topics.increasePostCount(postData.tid); | ||||
| 		Topics.updateTimestamp(postData.tid, postData.timestamp); | ||||
| 		Topics.addPostToTopic(postData.tid, postData.pid, postData.timestamp, 0); | ||||
| 	Topics.onNewPostMade = function(postData, callback) { | ||||
| 		async.parallel([ | ||||
| 			function(next) { | ||||
| 				Topics.increasePostCount(postData.tid, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				Topics.updateTimestamp(postData.tid, postData.timestamp, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				Topics.addPostToTopic(postData.tid, postData.pid, postData.timestamp, 0, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	emitter.on('event:newpost', Topics.onNewPostMade); | ||||
|  | ||||
| 	Topics.getTopicPosts = function(tid, set, start, end, uid, reverse, callback) { | ||||
| 		callback = callback || function() {}; | ||||
|   | ||||
| @@ -2,7 +2,10 @@ | ||||
|  | ||||
| 'use strict'; | ||||
|  | ||||
| var db = require('./../database'); | ||||
| var async = require('async'), | ||||
| 	db = require('../database'); | ||||
|  | ||||
|  | ||||
|  | ||||
| module.exports = function(Topics) { | ||||
| 	var terms = { | ||||
| @@ -33,9 +36,15 @@ module.exports = function(Topics) { | ||||
| 		db.getSortedSetRevRangeByScore('topics:recent', start, count, Infinity, Date.now() - since, callback); | ||||
| 	}; | ||||
|  | ||||
| 	Topics.updateTimestamp = function(tid, timestamp) { | ||||
| 		Topics.updateRecent(tid, timestamp); | ||||
| 		Topics.setTopicField(tid, 'lastposttime', timestamp); | ||||
| 	Topics.updateTimestamp = function(tid, timestamp, callback) { | ||||
| 		async.parallel([ | ||||
| 			function(next) { | ||||
| 				Topics.updateRecent(tid, timestamp, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				Topics.setTopicField(tid, 'lastposttime', timestamp, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	Topics.updateRecent = function(tid, timestamp, callback) { | ||||
|   | ||||
							
								
								
									
										24
									
								
								src/user.js
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/user.js
									
									
									
									
									
								
							| @@ -1,7 +1,6 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var | ||||
| 	async = require('async'), | ||||
| var	async = require('async'), | ||||
| 	nconf = require('nconf'), | ||||
| 	gravatar = require('gravatar'), | ||||
|  | ||||
| @@ -9,7 +8,6 @@ var | ||||
| 	db = require('./database'), | ||||
| 	meta = require('./meta'), | ||||
| 	groups = require('./groups'), | ||||
| 	emitter = require('./emitter'), | ||||
| 	Password = require('./password'); | ||||
|  | ||||
| (function(User) { | ||||
| @@ -298,16 +296,20 @@ var | ||||
| 		Password.hash(nconf.get('bcrypt_rounds'), password, callback); | ||||
| 	}; | ||||
|  | ||||
| 	User.onNewPostMade = function(postData) { | ||||
| 		User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp); | ||||
|  | ||||
| 		User.incrementUserPostCountBy(postData.uid, 1); | ||||
|  | ||||
| 		User.setUserField(postData.uid, 'lastposttime', postData.timestamp); | ||||
| 	User.onNewPostMade = function(postData, callback) { | ||||
| 		async.parallel([ | ||||
| 			function(next) { | ||||
| 				User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				User.incrementUserPostCountBy(postData.uid, 1, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				User.setUserField(postData.uid, 'lastposttime', postData.timestamp, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	emitter.on('event:newpost', User.onNewPostMade); | ||||
|  | ||||
| 	User.incrementUserPostCountBy = function(uid, value, callback) { | ||||
| 		callback = callback || function() {}; | ||||
| 		User.incrementUserFieldBy(uid, 'postcount', value, function(err, newpostcount) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user