mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	related to #1250
This commit is contained in:
		| @@ -63,19 +63,20 @@ define(function() { | ||||
| 							templates['users'].parse({users:[]}); | ||||
| 							var html = templates.prepare(templates['users'].blocks['users']).parse({ | ||||
| 								users: data.users | ||||
| 							}), | ||||
| 								userListEl = $('#users-container'); | ||||
| 							}); | ||||
|  | ||||
| 							userListEl.html(html); | ||||
| 							translator.translate(html, function(translated) { | ||||
| 								$('#users-container').html(translated); | ||||
|  | ||||
|  | ||||
| 							if (data && data.users.length === 0) { | ||||
| 								$('#user-notfound-notify').html('User not found!'); | ||||
| 								$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); | ||||
| 							} else { | ||||
| 								$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.'); | ||||
| 								$('#user-notfound-notify').parent().addClass('btn-success label-success'); | ||||
| 							} | ||||
| 								if (data && data.users.length === 0) { | ||||
| 									$('#user-notfound-notify').html('User not found!'); | ||||
| 									$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); | ||||
| 								} else { | ||||
| 									$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.'); | ||||
| 									$('#user-notfound-notify').parent().addClass('btn-success label-success'); | ||||
| 								} | ||||
| 							}); | ||||
| 						}); | ||||
| 					}); | ||||
| 				}, 500); //replace this with global throttling function/constant | ||||
|   | ||||
| @@ -26,7 +26,7 @@ usersController.sortByJoinDate = function(req, res, next) { | ||||
| }; | ||||
|  | ||||
| function getUsers(set, req, res, next) { | ||||
| 	user.getUsers(set, 0, 49, function(err, users) { | ||||
| 	user.getUsersFromSet(set, 0, 49, function(err, users) { | ||||
| 		if (err) { | ||||
| 			return next(err); | ||||
| 		} | ||||
|   | ||||
| @@ -9,7 +9,7 @@ var async = require('async'), | ||||
| usersController.getOnlineUsers = function(req, res, next) { | ||||
| 	var	websockets = require('../socket.io'); | ||||
|  | ||||
| 	user.getUsers('users:online', 0, 49, function (err, data) { | ||||
| 	user.getUsersFromSet('users:online', 0, 49, function (err, data) { | ||||
| 		if(err) { | ||||
| 			return next(err); | ||||
| 		} | ||||
| @@ -72,7 +72,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) { | ||||
| }; | ||||
|  | ||||
| function getUsers(set, res, next) { | ||||
| 	user.getUsers(set, 0, 49, function (err, data) { | ||||
| 	user.getUsersFromSet(set, 0, 49, function (err, data) { | ||||
| 		if (err) { | ||||
| 			return next(err); | ||||
| 		} | ||||
|   | ||||
| @@ -4,6 +4,7 @@ var	async = require('async'), | ||||
| 	user = require('../user'), | ||||
| 	topics = require('../topics'), | ||||
| 	utils = require('./../../public/src/utils'), | ||||
| 	meta = require('../meta'), | ||||
| 	SocketUser = {}; | ||||
|  | ||||
| SocketUser.exists = function(socket, data, callback) { | ||||
| @@ -204,6 +205,10 @@ SocketUser.loadMore = function(socket, data, callback) { | ||||
| 		return callback(new Error('invalid-data')); | ||||
| 	} | ||||
|  | ||||
| 	if (!socket.uid && !!parseInt(meta.config.privateUserInfo, 10)) { | ||||
| 		return callback(new Error('not-allowed')); | ||||
| 	} | ||||
|  | ||||
| 	var start = data.after, | ||||
| 		end = start + 19; | ||||
|  | ||||
| @@ -231,7 +236,6 @@ SocketUser.loadMore = function(socket, data, callback) { | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
| SocketUser.setStatus = function(socket, status, callback) { | ||||
| 	var server = require('./index'); | ||||
| 	user.setUserField(socket.uid, 'status', status, function(err) { | ||||
|   | ||||
							
								
								
									
										38
									
								
								src/user.js
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								src/user.js
									
									
									
									
									
								
							| @@ -142,7 +142,18 @@ var bcrypt = require('bcryptjs'), | ||||
| 		db.incrObjectFieldBy('user:' + uid, field, -value, callback); | ||||
| 	}; | ||||
|  | ||||
| 	User.getUsers = function(set, start, stop, callback) { | ||||
| 	User.getUsersFromSet = function(set, start, stop, callback) { | ||||
| 		async.waterfall([ | ||||
| 			function(next) { | ||||
| 				db.getSortedSetRevRange(set, start, stop, next); | ||||
| 			}, | ||||
| 			function(uids, next) { | ||||
| 				User.getUsers(uids, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|  | ||||
| 	User.getUsers = function(uids, callback) { | ||||
| 		function loadUserInfo(user, callback) { | ||||
| 			if (!user) { | ||||
| 				return callback(null, user); | ||||
| @@ -155,13 +166,10 @@ var bcrypt = require('bcryptjs'), | ||||
| 				function(isAdmin, next) { | ||||
| 					user.status = !user.status ? 'online' : user.status; | ||||
| 					user.administrator = isAdmin ? '1':'0'; | ||||
| 					if (set === 'users:online') { | ||||
| 						return callback(null, user); | ||||
| 					} | ||||
| 					db.sortedSetScore('users:online', user.uid, next); | ||||
| 					db.isSortedSetMember('users:online', user.uid, next); | ||||
| 				}, | ||||
| 				function(score, next) { | ||||
| 					if (!score) { | ||||
| 				function(isMember, next) { | ||||
| 					if (!isMember) { | ||||
| 						user.status = 'offline'; | ||||
| 					} | ||||
| 					next(null, user); | ||||
| @@ -169,17 +177,13 @@ var bcrypt = require('bcryptjs'), | ||||
| 			], callback); | ||||
| 		} | ||||
|  | ||||
| 		async.waterfall([ | ||||
| 			function(next) { | ||||
| 				db.getSortedSetRevRange(set, start, stop, next); | ||||
| 			}, | ||||
| 			function(uids, next) { | ||||
| 				User.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation'], next); | ||||
| 			}, | ||||
| 			function(users, next) { | ||||
| 				async.map(users, loadUserInfo, next); | ||||
| 		User.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation'], function(err, usersData) { | ||||
| 			if (err) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
| 		], callback); | ||||
|  | ||||
| 			async.map(usersData, loadUserInfo, callback); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| 	User.createGravatarURLFromEmail = function(email) { | ||||
|   | ||||
| @@ -31,10 +31,11 @@ module.exports = function(User) { | ||||
| 				return usernamesHash[username]; | ||||
| 			}); | ||||
|  | ||||
| 			User.getUsersData(uids, function(err, userdata) { | ||||
| 			User.getUsers(uids, function(err, userdata) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
|  | ||||
| 				var diff = process.hrtime(start); | ||||
| 				var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1); | ||||
| 				callback(null, {timing: timing, users: userdata}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user