diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 17944b8370..283302b48e 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -31,7 +31,8 @@ usersController.banned = function(req, res, next) { }; function getUsers(set, req, res, next) { - user.getUsersFromSet(set, 0, 49, function(err, users) { + var uid = req.user ? parseInt(req.user.uid, 10) : 0; + user.getUsersFromSet(set, uid, 0, 49, function(err, users) { if (err) { return next(err); } diff --git a/src/controllers/groups.js b/src/controllers/groups.js index c20993a7df..18ea0cbf2d 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -49,12 +49,13 @@ groupsController.details = function(req, res, next) { }; groupsController.members = function(req, res, next) { + var uid = req.user ? parseInt(req.user.uid, 10) : 0; async.waterfall([ function(next) { groups.getGroupNameByGroupSlug(req.params.slug, next); }, function(groupName, next) { - user.getUsersFromSet('group:' + groupName + ':members', 0, 49, next); + user.getUsersFromSet('group:' + groupName + ':members', uid, 0, 49, next); }, ], function(err, users) { if (err) { diff --git a/src/controllers/users.js b/src/controllers/users.js index 0a2d4d0d67..81001d0f3a 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -14,7 +14,7 @@ usersController.getOnlineUsers = function(req, res, next) { async.parallel({ users: function(next) { - user.getUsersFromSet('users:online', 0, 49, next); + user.getUsersFromSet('users:online', uid, 0, 49, next); }, count: function(next) { var now = Date.now(); @@ -63,7 +63,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) { usersController.getUsers = function(set, count, req, res, next) { var uid = req.user ? req.user.uid : 0; - getUsersAndCount(set, count, function(err, data) { + getUsersAndCount(set, uid, count, function(err, data) { if (err) { return next(err); } @@ -78,10 +78,10 @@ usersController.getUsers = function(set, count, req, res, next) { }); }; -function getUsersAndCount(set, count, callback) { +function getUsersAndCount(set, uid, count, callback) { async.parallel({ users: function(next) { - user.getUsersFromSet(set, 0, count - 1, next); + user.getUsersFromSet(set, uid, 0, count - 1, next); }, count: function(next) { db.getObjectField('global', 'userCount', next); @@ -102,7 +102,7 @@ usersController.getUsersForSearch = function(req, res, next) { var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20, uid = req.user ? req.user.uid : 0; - getUsersAndCount('users:joindate', resultsPerPage, function(err, data) { + getUsersAndCount('users:joindate', uid, resultsPerPage, function(err, data) { if (err) { return next(err); } diff --git a/src/search.js b/src/search.js index c4a830f41a..e0be3ecafd 100644 --- a/src/search.js +++ b/src/search.js @@ -40,7 +40,7 @@ search.search = function(data, callback) { if (searchIn === 'posts') { searchInPosts(query, data.postedBy, uid, done); } else if (searchIn === 'users') { - searchInUsers(query, done); + searchInUsers(query, uid, done); } else if (searchIn === 'tags') { searchInTags(query, done); } else { @@ -99,8 +99,8 @@ function searchInPosts(query, postedBy, uid, callback) { }); } -function searchInUsers(query, callback) { - user.search({query: query}, function(err, results) { +function searchInUsers(query, uid, callback) { + user.search({query: query, uid: uid}, function(err, results) { callback(err, results ? results.users : null); }); } diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 2ba036d7e0..9a9ef0ea7e 100644 --- a/src/socket.io/admin/categories.js +++ b/src/socket.io/admin/categories.js @@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) { var username = data.username, cid = data.cid; - user.search({query: username}, function(err, data) { + user.search({query: username, uid: socket.uid}, function(err, data) { if (err) { return callback(err); } diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js index 9189727fbb..5f7199bf29 100644 --- a/src/socket.io/admin/user.js +++ b/src/socket.io/admin/user.js @@ -175,7 +175,7 @@ User.deleteUsers = function(socket, uids, callback) { }; User.search = function(socket, data, callback) { - user.search({query: data.query, searchBy: data.searchBy, startsWith: false}, function(err, searchData) { + user.search({query: data.query, searchBy: data.searchBy, startsWith: false, uid: socket.uid}, function(err, searchData) { if (err) { return callback(err); } diff --git a/src/socket.io/user.js b/src/socket.io/user.js index d28421c383..6004bdd469 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -66,7 +66,8 @@ SocketUser.search = function(socket, data, callback) { page: data.page, searchBy: data.searchBy, sortBy: data.sortBy, - filterBy: data.filterBy + filterBy: data.filterBy, + uid: socket.uid }, callback); }; @@ -332,7 +333,7 @@ SocketUser.loadMore = function(socket, data, callback) { var start = parseInt(data.after, 10), end = start + 19; - user.getUsersFromSet(data.set, start, end, function(err, userData) { + user.getUsersFromSet(data.set, socket.uid, start, end, function(err, userData) { if (err) { return callback(err); } diff --git a/src/user.js b/src/user.js index 80f7a951db..c7d8649d22 100644 --- a/src/user.js +++ b/src/user.js @@ -219,18 +219,18 @@ var async = require('async'), } }; - User.getUsersFromSet = function(set, start, stop, callback) { + User.getUsersFromSet = function(set, uid, start, stop, callback) { async.waterfall([ function(next) { User.getUidsFromSet(set, start, stop, next); }, function(uids, next) { - User.getUsers(uids, next); + User.getUsers(uids, uid, next); } ], callback); }; - User.getUsers = function(uids, callback) { + User.getUsers = function(uids, uid, callback) { var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation', 'email:confirmed']; plugins.fireHook('filter:users.addFields', {fields: fields}, function(err, data) { if (err) { @@ -264,7 +264,7 @@ var async = require('async'), user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1; }); - plugins.fireHook('filter:userlist.get', {users: results.userData}, function(err, data) { + plugins.fireHook('filter:userlist.get', {users: results.userData, uid: uid}, function(err, data) { if (err) { return callback(err); } diff --git a/src/user/follow.js b/src/user/follow.js index c3e2cb340c..6b0c0a3973 100644 --- a/src/user/follow.js +++ b/src/user/follow.js @@ -59,7 +59,7 @@ module.exports = function(User) { return callback(err); } - User.getUsers(uids, callback); + User.getUsers(uids, uid, callback); }); } diff --git a/src/user/search.js b/src/user/search.js index 95130bf68f..9df346f6ec 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -14,13 +14,14 @@ module.exports = function(User) { var searchBy = data.searchBy || ['username']; var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true; var page = data.page || 1; + var uid = data.uid || 0; if (!query) { return callback(null, {timing: 0, users: [], matchCount: 0, pages: []}); } if (searchBy.indexOf('ip') !== -1) { - return searchByIP(query, callback); + return searchByIP(query, uid, callback); } var startTime = process.hrtime(); @@ -46,7 +47,7 @@ module.exports = function(User) { matchCount = uids.length; uids = uids.slice(start, end); - User.getUsers(uids, next); + User.getUsers(uids, uid, next); }, function(userData, next) { @@ -194,14 +195,14 @@ module.exports = function(User) { } } - function searchByIP(ip, callback) { + function searchByIP(ip, uid, callback) { var start = process.hrtime(); async.waterfall([ function(next) { db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next); }, function(uids, next) { - User.getUsers(uids, next); + User.getUsers(uids, uid, next); }, function(users, next) { var diff = process.hrtime(start);