From da0b2c84e675ec03fc4f73568c65d97afa23036e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 30 Jan 2015 16:24:57 -0500 Subject: [PATCH] passing memberCount and createTime into getUserGroups --- src/groups.js | 54 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/groups.js b/src/groups.js index 4a7611c531..4eca55c05d 100644 --- a/src/groups.js +++ b/src/groups.js @@ -781,35 +781,51 @@ var async = require('async'), groupData = groupData.filter(function(group) { return parseInt(group.hidden, 10) !== 1 && !!group.userTitle; + }).map(function(group) { + group.createtimeISO = utils.toISOString(group.createtime); + return group; }); - var groupSets = groupData.map(function(group) { - group.labelColor = group.labelColor || '#000000'; + async.map(groupData, function(groupObj, next) { + Groups.getMemberCount(groupObj.name, function(err, memberCount) { + if (err) { return next(err); } - if (!group['cover:url']) { - group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png'; - group['cover:position'] = '50% 50%'; + groupObj.memberCount = memberCount; + next(err, groupObj); + }); + }, function(err, groupData) { + if (err) { + return callback(err); } - return 'group:' + group.name + ':members'; - }); + var groupSets = groupData.map(function(group) { + group.labelColor = group.labelColor || '#000000'; - async.map(uids, function(uid, next) { - db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) { - if (err) { - return next(err); + if (!group['cover:url']) { + group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png'; + group['cover:position'] = '50% 50%'; } - var memberOf = []; - isMembers.forEach(function(isMember, index) { - if (isMember) { - memberOf.push(groupData[index]); + return 'group:' + group.name + ':members'; + }); + + async.map(uids, function(uid, next) { + db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) { + if (err) { + return next(err); } - }); - next(null, memberOf); - }); - }, callback); + var memberOf = []; + isMembers.forEach(function(isMember, index) { + if (isMember) { + memberOf.push(groupData[index]); + } + }); + + next(null, memberOf); + }); + }, callback); + }); }); }); };