mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	closes #206
This commit is contained in:
		| @@ -74,6 +74,7 @@ var	RDB = require('./redis.js'), | |||||||
| 						categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none'; | 						categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none'; | ||||||
| 						categoryData.moderators = results[1]; | 						categoryData.moderators = results[1]; | ||||||
| 						categoryData.active_users = results[2]; | 						categoryData.active_users = results[2]; | ||||||
|  | 						categoryData.show_sidebar = categoryData.topics.length > 0 ? 'show':'hidden'; | ||||||
| 						callback(null, categoryData); | 						callback(null, categoryData); | ||||||
| 					}); | 					}); | ||||||
| 				} | 				} | ||||||
| @@ -234,6 +235,26 @@ var	RDB = require('./redis.js'), | |||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	Categories.moveActiveUsers = function(tid, oldCid, cid, callback) { | ||||||
|  | 		topics.getUids(tid, function(err, uids) { | ||||||
|  | 			if(!err && uids) { | ||||||
|  | 				function updateUser(uid) { | ||||||
|  | 					Categories.addActiveUser(cid, uid); | ||||||
|  | 					Categories.isUserActiveIn(oldCid, uid, function(err, active) { | ||||||
|  |  | ||||||
|  | 						if(!err && !active) { | ||||||
|  | 							Categories.removeActiveUser(oldCid, uid); | ||||||
|  | 						} | ||||||
|  | 					}); | ||||||
|  | 				} | ||||||
|  |  | ||||||
|  | 				for(var i=0; i<uids.length; ++i) { | ||||||
|  | 					updateUser(uids[i]); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	Categories.getCategoryData = function(cid, callback) { | 	Categories.getCategoryData = function(cid, callback) { | ||||||
| 		RDB.exists('category:' + cid, function(err, exists) { | 		RDB.exists('category:' + cid, function(err, exists) { | ||||||
| 			if (exists) RDB.hgetall('category:' + cid, callback); | 			if (exists) RDB.hgetall('category:' + cid, callback); | ||||||
| @@ -299,5 +320,58 @@ var	RDB = require('./redis.js'), | |||||||
|  |  | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	Categories.isUserActiveIn = function(cid, uid, callback) { | ||||||
|  |  | ||||||
|  | 		RDB.lrange('uid:' + uid + ':posts', 0, -1, function(err, pids) { | ||||||
|  | 			if(err) | ||||||
|  | 				return callback(err, null); | ||||||
|  |  | ||||||
|  | 			function getPostCategory(pid, callback) { | ||||||
|  | 				posts.getPostField(pid, 'tid', function(tid) { | ||||||
|  |  | ||||||
|  | 					topics.getTopicField(tid, 'cid', function(err, postCid) { | ||||||
|  | 						if(err) | ||||||
|  | 							return callback(err, null); | ||||||
|  |  | ||||||
|  | 						return callback(null, postCid); | ||||||
|  | 					}); | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			var index = 0, | ||||||
|  | 				active = false; | ||||||
|  |  | ||||||
|  | 			async.whilst( | ||||||
|  | 				function() { | ||||||
|  | 					return active === false && index < pids.length; | ||||||
|  | 				}, | ||||||
|  | 				function(callback) { | ||||||
|  | 					getPostCategory(pids[index], function(err, postCid) { | ||||||
|  | 						if(err) | ||||||
|  | 							return callback(err); | ||||||
|  | 						if(postCid === cid) | ||||||
|  | 							active = true; | ||||||
|  | 						++index; | ||||||
|  | 						callback(null); | ||||||
|  | 					}) | ||||||
|  | 				}, | ||||||
|  | 				function(err) { | ||||||
|  | 					if(err) | ||||||
|  | 						return callback(err, null); | ||||||
|  |  | ||||||
|  | 					callback(null, active); | ||||||
|  | 				} | ||||||
|  | 			); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	Categories.addActiveUser = function(cid, uid) { | ||||||
|  | 		RDB.sadd('cid:' + cid + ':active_users', uid); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	Categories.removeActiveUser = function(cid, uid) { | ||||||
|  | 		RDB.srem('cid:' + cid + ':active_users', uid); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| }(exports)); | }(exports)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ var	fs = require('fs'), | |||||||
| 				hookList = this.loadedHooks[hook]; | 				hookList = this.loadedHooks[hook]; | ||||||
|  |  | ||||||
| 			if (hookList && Array.isArray(hookList)) { | 			if (hookList && Array.isArray(hookList)) { | ||||||
| 				if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\''); | 				//if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\''); | ||||||
| 				var	hookType = hook.split(':')[0]; | 				var	hookType = hook.split(':')[0]; | ||||||
| 				switch(hookType) { | 				switch(hookType) { | ||||||
| 					case 'filter': | 					case 'filter': | ||||||
|   | |||||||
| @@ -310,7 +310,7 @@ var	RDB = require('./redis.js'), | |||||||
| 									RDB.spop('cid:' + cid + ':active_users'); | 									RDB.spop('cid:' + cid + ':active_users'); | ||||||
| 								} | 								} | ||||||
|  |  | ||||||
| 								RDB.sadd('cid:' + cid + ':active_users', uid); | 								categories.addActiveUser(cid, uid); | ||||||
| 							}); | 							}); | ||||||
| 						}); | 						}); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -199,12 +199,19 @@ var	RDB = require('./redis.js'), | |||||||
| 						} | 						} | ||||||
| 					}); | 					}); | ||||||
|  |  | ||||||
|  | 					categories.moveActiveUsers(tid, oldCid, cid, function(err, data) { | ||||||
|  | 						if(err) { | ||||||
|  | 							winston.err(err); | ||||||
|  | 						} | ||||||
|  | 					}); | ||||||
|  |  | ||||||
| 					categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1); | 					categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1); | ||||||
| 					categories.incrementCategoryFieldBy(cid, 'topic_count', 1); | 					categories.incrementCategoryFieldBy(cid, 'topic_count', 1); | ||||||
|  |  | ||||||
| 					socket.emit('api:topic.move', { | 					socket.emit('api:topic.move', { | ||||||
| 						status: 'ok' | 						status: 'ok' | ||||||
| 					}); | 					}); | ||||||
|  |  | ||||||
| 					io.sockets.in('topic_' + tid).emit('event:topic_moved', { | 					io.sockets.in('topic_' + tid).emit('event:topic_moved', { | ||||||
| 						tid: tid | 						tid: tid | ||||||
| 					}); | 					}); | ||||||
|   | |||||||
| @@ -722,6 +722,28 @@ marked.setOptions({ | |||||||
| 		RDB.lrange('tid:' + tid + ':posts', 0, -1, callback); | 		RDB.lrange('tid:' + tid + ':posts', 0, -1, callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	Topics.getUids = function(tid, callback) { | ||||||
|  | 		var uids = {}; | ||||||
|  | 		Topics.getPids(tid, function(err, pids) { | ||||||
|  |  | ||||||
|  | 			function getUid(pid, next) { | ||||||
|  | 				posts.getPostField(pid, 'uid', function(uid) { | ||||||
|  | 					if(err) | ||||||
|  | 						return next(err); | ||||||
|  | 					uids[uid] = 1; | ||||||
|  | 					next(null); | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			async.each(pids, getUid, function(err) { | ||||||
|  | 				if(err) | ||||||
|  | 					return callback(err, null); | ||||||
|  |  | ||||||
|  | 				callback(null, Object.keys(uids)); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	Topics.delete = function(tid) { | 	Topics.delete = function(tid) { | ||||||
| 		Topics.setTopicField(tid, 'deleted', 1); | 		Topics.setTopicField(tid, 'deleted', 1); | ||||||
| 		RDB.zrem('topics:recent', tid); | 		RDB.zrem('topics:recent', tid); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user