mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
new group members route
getMembers can take start end ability to specify how many group members to return
This commit is contained in:
@@ -130,7 +130,7 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Categories.getModerators = function(cid, callback) {
|
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) {
|
if (err || !Array.isArray(uids) || !uids.length) {
|
||||||
return callback(err, []);
|
return callback(err, []);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var groups = require('../groups'),
|
var async = require('async'),
|
||||||
async = require('async'),
|
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
groups = require('../groups'),
|
||||||
|
user = require('../user'),
|
||||||
helpers = require('./helpers'),
|
helpers = require('./helpers'),
|
||||||
groupsController = {};
|
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;
|
module.exports = groupsController;
|
||||||
|
|||||||
@@ -113,9 +113,10 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.truncateUserList) {
|
if (options.truncateUserList) {
|
||||||
if (uids.length > 4) {
|
var userListCount = parseInt(options.userListCount, 10) || 4;
|
||||||
|
if (uids.length > userListCount) {
|
||||||
numUsers = uids.length;
|
numUsers = uids.length;
|
||||||
uids.length = 4;
|
uids.length = userListCount;
|
||||||
truncated = true;
|
truncated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,8 +272,8 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Groups.getMembers = function(groupName, callback) {
|
Groups.getMembers = function(groupName, start, end, callback) {
|
||||||
db.getSortedSetRevRange('group:' + groupName + ':members', 0, -1, callback);
|
db.getSortedSetRevRange('group:' + groupName + ':members', start, end, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Groups.isMember = function(uid, groupName, callback) {
|
Groups.isMember = function(uid, groupName, callback) {
|
||||||
@@ -761,7 +762,9 @@ var async = require('async'),
|
|||||||
Groups.getLatestMemberPosts = function(groupSlug, max, uid, callback) {
|
Groups.getLatestMemberPosts = function(groupSlug, max, uid, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(Groups.getGroupNameByGroupSlug, groupSlug),
|
async.apply(Groups.getGroupNameByGroupSlug, groupSlug),
|
||||||
Groups.getMembers,
|
function(groupName, next) {
|
||||||
|
Groups.getMembers(groupName, 0, -1, next);
|
||||||
|
},
|
||||||
function(uids, next) {
|
function(uids, next) {
|
||||||
if (!Array.isArray(uids) || !uids.length) {
|
if (!Array.isArray(uids) || !uids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ function groupRoutes(app, middleware, controllers) {
|
|||||||
|
|
||||||
setupPageRoute(app, '/groups', middleware, middlewares, controllers.groups.list);
|
setupPageRoute(app, '/groups', middleware, middlewares, controllers.groups.list);
|
||||||
setupPageRoute(app, '/groups/:slug', middleware, middlewares, controllers.groups.details);
|
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) {
|
function setupPageRoute(router, name, middleware, middlewares, controller) {
|
||||||
|
|||||||
@@ -403,10 +403,10 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
function(post, next) {
|
function(post, next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
admins: function(next) {
|
admins: function(next) {
|
||||||
groups.getMembers('administrators', next);
|
groups.getMembers('administrators', 0, -1, next);
|
||||||
},
|
},
|
||||||
moderators: function(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);
|
}, next);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user