pass uid to getUsers and getUsersFromSets

v1.18.x
barisusakli 10 years ago
parent 6ebc048f1f
commit b54f2de504

@ -31,7 +31,8 @@ usersController.banned = function(req, res, next) {
}; };
function getUsers(set, 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) { if (err) {
return next(err); return next(err);
} }

@ -49,12 +49,13 @@ groupsController.details = function(req, res, next) {
}; };
groupsController.members = function(req, res, next) { groupsController.members = function(req, res, next) {
var uid = req.user ? parseInt(req.user.uid, 10) : 0;
async.waterfall([ async.waterfall([
function(next) { function(next) {
groups.getGroupNameByGroupSlug(req.params.slug, next); groups.getGroupNameByGroupSlug(req.params.slug, next);
}, },
function(groupName, next) { function(groupName, next) {
user.getUsersFromSet('group:' + groupName + ':members', 0, 49, next); user.getUsersFromSet('group:' + groupName + ':members', uid, 0, 49, next);
}, },
], function(err, users) { ], function(err, users) {
if (err) { if (err) {

@ -14,7 +14,7 @@ usersController.getOnlineUsers = function(req, res, next) {
async.parallel({ async.parallel({
users: function(next) { users: function(next) {
user.getUsersFromSet('users:online', 0, 49, next); user.getUsersFromSet('users:online', uid, 0, 49, next);
}, },
count: function(next) { count: function(next) {
var now = Date.now(); var now = Date.now();
@ -63,7 +63,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) {
usersController.getUsers = function(set, count, req, res, next) { usersController.getUsers = function(set, count, req, res, next) {
var uid = req.user ? req.user.uid : 0; var uid = req.user ? req.user.uid : 0;
getUsersAndCount(set, count, function(err, data) { getUsersAndCount(set, uid, count, function(err, data) {
if (err) { if (err) {
return next(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({ async.parallel({
users: function(next) { users: function(next) {
user.getUsersFromSet(set, 0, count - 1, next); user.getUsersFromSet(set, uid, 0, count - 1, next);
}, },
count: function(next) { count: function(next) {
db.getObjectField('global', 'userCount', next); db.getObjectField('global', 'userCount', next);
@ -102,7 +102,7 @@ usersController.getUsersForSearch = function(req, res, next) {
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20, var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20,
uid = req.user ? req.user.uid : 0; uid = req.user ? req.user.uid : 0;
getUsersAndCount('users:joindate', resultsPerPage, function(err, data) { getUsersAndCount('users:joindate', uid, resultsPerPage, function(err, data) {
if (err) { if (err) {
return next(err); return next(err);
} }

@ -40,7 +40,7 @@ search.search = function(data, callback) {
if (searchIn === 'posts') { if (searchIn === 'posts') {
searchInPosts(query, data.postedBy, uid, done); searchInPosts(query, data.postedBy, uid, done);
} else if (searchIn === 'users') { } else if (searchIn === 'users') {
searchInUsers(query, done); searchInUsers(query, uid, done);
} else if (searchIn === 'tags') { } else if (searchIn === 'tags') {
searchInTags(query, done); searchInTags(query, done);
} else { } else {
@ -99,8 +99,8 @@ function searchInPosts(query, postedBy, uid, callback) {
}); });
} }
function searchInUsers(query, callback) { function searchInUsers(query, uid, callback) {
user.search({query: query}, function(err, results) { user.search({query: query, uid: uid}, function(err, results) {
callback(err, results ? results.users : null); callback(err, results ? results.users : null);
}); });
} }

@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) {
var username = data.username, var username = data.username,
cid = data.cid; cid = data.cid;
user.search({query: username}, function(err, data) { user.search({query: username, uid: socket.uid}, function(err, data) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

@ -175,7 +175,7 @@ User.deleteUsers = function(socket, uids, callback) {
}; };
User.search = function(socket, data, 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) { if (err) {
return callback(err); return callback(err);
} }

@ -66,7 +66,8 @@ SocketUser.search = function(socket, data, callback) {
page: data.page, page: data.page,
searchBy: data.searchBy, searchBy: data.searchBy,
sortBy: data.sortBy, sortBy: data.sortBy,
filterBy: data.filterBy filterBy: data.filterBy,
uid: socket.uid
}, callback); }, callback);
}; };
@ -332,7 +333,7 @@ SocketUser.loadMore = function(socket, data, callback) {
var start = parseInt(data.after, 10), var start = parseInt(data.after, 10),
end = start + 19; 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) { if (err) {
return callback(err); return callback(err);
} }

@ -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([ async.waterfall([
function(next) { function(next) {
User.getUidsFromSet(set, start, stop, next); User.getUidsFromSet(set, start, stop, next);
}, },
function(uids, next) { function(uids, next) {
User.getUsers(uids, next); User.getUsers(uids, uid, next);
} }
], callback); ], callback);
}; };
User.getUsers = function(uids, callback) { User.getUsers = function(uids, uid, callback) {
var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation', 'email:confirmed']; var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation', 'email:confirmed'];
plugins.fireHook('filter:users.addFields', {fields: fields}, function(err, data) { plugins.fireHook('filter:users.addFields', {fields: fields}, function(err, data) {
if (err) { if (err) {
@ -264,7 +264,7 @@ var async = require('async'),
user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1; 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) { if (err) {
return callback(err); return callback(err);
} }

@ -59,7 +59,7 @@ module.exports = function(User) {
return callback(err); return callback(err);
} }
User.getUsers(uids, callback); User.getUsers(uids, uid, callback);
}); });
} }

@ -14,13 +14,14 @@ module.exports = function(User) {
var searchBy = data.searchBy || ['username']; var searchBy = data.searchBy || ['username'];
var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true; var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true;
var page = data.page || 1; var page = data.page || 1;
var uid = data.uid || 0;
if (!query) { if (!query) {
return callback(null, {timing: 0, users: [], matchCount: 0, pages: []}); return callback(null, {timing: 0, users: [], matchCount: 0, pages: []});
} }
if (searchBy.indexOf('ip') !== -1) { if (searchBy.indexOf('ip') !== -1) {
return searchByIP(query, callback); return searchByIP(query, uid, callback);
} }
var startTime = process.hrtime(); var startTime = process.hrtime();
@ -46,7 +47,7 @@ module.exports = function(User) {
matchCount = uids.length; matchCount = uids.length;
uids = uids.slice(start, end); uids = uids.slice(start, end);
User.getUsers(uids, next); User.getUsers(uids, uid, next);
}, },
function(userData, 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(); var start = process.hrtime();
async.waterfall([ async.waterfall([
function(next) { function(next) {
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next); db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next);
}, },
function(uids, next) { function(uids, next) {
User.getUsers(uids, next); User.getUsers(uids, uid, next);
}, },
function(users, next) { function(users, next) {
var diff = process.hrtime(start); var diff = process.hrtime(start);

Loading…
Cancel
Save