From 57453f33ab1fd71fb929bd8a35be310e1cb066ae Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 29 Jan 2015 13:37:45 -0500 Subject: [PATCH] new group members route getMembers can take start end ability to specify how many group members to return --- src/categories.js | 2 +- src/controllers/groups.js | 26 ++++++++++++++++++++++++-- src/groups.js | 13 ++++++++----- src/routes/index.js | 1 + src/socket.io/posts.js | 4 ++-- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/categories.js b/src/categories.js index 574e435081..22c7807c96 100644 --- a/src/categories.js +++ b/src/categories.js @@ -130,7 +130,7 @@ var async = require('async'), }; Categories.getModerators = function(cid, callback) { - Groups.getMembers('cid:' + cid + ':privileges:mods', function(err, uids) { + Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, function(err, uids) { if (err || !Array.isArray(uids) || !uids.length) { return callback(err, []); } diff --git a/src/controllers/groups.js b/src/controllers/groups.js index f72d7ed1d4..c20993a7df 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -1,8 +1,9 @@ "use strict"; -var groups = require('../groups'), - async = require('async'), +var async = require('async'), nconf = require('nconf'), + groups = require('../groups'), + user = require('../user'), helpers = require('./helpers'), groupsController = {}; @@ -47,4 +48,25 @@ groupsController.details = function(req, res, next) { }); }; +groupsController.members = function(req, res, next) { + async.waterfall([ + function(next) { + groups.getGroupNameByGroupSlug(req.params.slug, next); + }, + function(groupName, next) { + user.getUsersFromSet('group:' + groupName + ':members', 0, 49, next); + }, + ], function(err, users) { + if (err) { + return next(err); + } + + res.render('groups/members', { + users: users, + nextStart: 50, + loadmore_display: users.length > 50 ? 'block' : 'hide', + }); + }); +}; + module.exports = groupsController; diff --git a/src/groups.js b/src/groups.js index e228ffbcf0..bd832a9178 100644 --- a/src/groups.js +++ b/src/groups.js @@ -113,9 +113,10 @@ var async = require('async'), } if (options.truncateUserList) { - if (uids.length > 4) { + var userListCount = parseInt(options.userListCount, 10) || 4; + if (uids.length > userListCount) { numUsers = uids.length; - uids.length = 4; + uids.length = userListCount; truncated = true; } } @@ -271,8 +272,8 @@ var async = require('async'), }); }; - Groups.getMembers = function(groupName, callback) { - db.getSortedSetRevRange('group:' + groupName + ':members', 0, -1, callback); + Groups.getMembers = function(groupName, start, end, callback) { + db.getSortedSetRevRange('group:' + groupName + ':members', start, end, callback); }; Groups.isMember = function(uid, groupName, callback) { @@ -761,7 +762,9 @@ var async = require('async'), Groups.getLatestMemberPosts = function(groupSlug, max, uid, callback) { async.waterfall([ async.apply(Groups.getGroupNameByGroupSlug, groupSlug), - Groups.getMembers, + function(groupName, next) { + Groups.getMembers(groupName, 0, -1, next); + }, function(uids, next) { if (!Array.isArray(uids) || !uids.length) { return callback(null, []); diff --git a/src/routes/index.js b/src/routes/index.js index b4427f90f1..1af03e0930 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -94,6 +94,7 @@ function groupRoutes(app, middleware, controllers) { setupPageRoute(app, '/groups', middleware, middlewares, controllers.groups.list); setupPageRoute(app, '/groups/:slug', middleware, middlewares, controllers.groups.details); + setupPageRoute(app, '/groups/:slug/members', middleware, middlewares, controllers.groups.members); } function setupPageRoute(router, name, middleware, middlewares, controller) { diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index f6b599884e..71e5577178 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -403,10 +403,10 @@ SocketPosts.flag = function(socket, pid, callback) { function(post, next) { async.parallel({ admins: function(next) { - groups.getMembers('administrators', next); + groups.getMembers('administrators', 0, -1, next); }, moderators: function(next) { - groups.getMembers('cid:' + post.topic.cid + ':privileges:mods', next); + groups.getMembers('cid:' + post.topic.cid + ':privileges:mods', 0, -1, next); } }, next); },