2014-03-09 23:51:09 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-09-20 23:04:49 -04:00
|
|
|
var async = require('async'),
|
|
|
|
|
winston = require('winston'),
|
2015-01-12 20:34:15 -05:00
|
|
|
nconf = require('nconf'),
|
2015-01-16 17:02:58 -05:00
|
|
|
validator = require('validator'),
|
2015-01-12 20:34:15 -05:00
|
|
|
|
2014-09-20 23:04:49 -04:00
|
|
|
user = require('./user'),
|
|
|
|
|
db = require('./database'),
|
2014-09-27 00:54:51 +02:00
|
|
|
plugins = require('./plugins'),
|
2014-09-20 23:04:49 -04:00
|
|
|
posts = require('./posts'),
|
2014-11-30 12:52:16 -05:00
|
|
|
privileges = require('./privileges'),
|
2015-05-28 15:27:55 -04:00
|
|
|
utils = require('../public/src/utils');
|
2014-09-20 23:04:49 -04:00
|
|
|
|
2013-11-27 11:21:16 -05:00
|
|
|
(function(Groups) {
|
2014-04-09 14:37:16 -04:00
|
|
|
|
2015-05-26 13:17:49 -04:00
|
|
|
require('./groups/create')(Groups);
|
|
|
|
|
require('./groups/delete')(Groups);
|
|
|
|
|
require('./groups/update')(Groups);
|
2015-05-26 14:45:17 -04:00
|
|
|
require('./groups/membership')(Groups);
|
|
|
|
|
require('./groups/ownership')(Groups);
|
|
|
|
|
require('./groups/search')(Groups);
|
2015-05-26 13:17:49 -04:00
|
|
|
|
|
|
|
|
var ephemeralGroups = ['guests'],
|
2014-05-14 16:13:30 -04:00
|
|
|
|
|
|
|
|
internals = {
|
2015-02-18 15:33:21 -05:00
|
|
|
getEphemeralGroup: function(groupName) {
|
|
|
|
|
return {
|
|
|
|
|
name: groupName,
|
2015-03-25 16:09:38 -04:00
|
|
|
slug: utils.slugify(groupName),
|
2015-02-18 15:33:21 -05:00
|
|
|
description: '',
|
|
|
|
|
deleted: '0',
|
|
|
|
|
hidden: '0',
|
|
|
|
|
system: '1'
|
|
|
|
|
};
|
2014-05-16 16:28:35 -04:00
|
|
|
},
|
|
|
|
|
removeEphemeralGroups: function(groups) {
|
|
|
|
|
var x = groups.length;
|
|
|
|
|
while(x--) {
|
|
|
|
|
if (ephemeralGroups.indexOf(groups[x]) !== -1) {
|
|
|
|
|
groups.splice(x, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groups;
|
2015-05-26 13:17:49 -04:00
|
|
|
}
|
2014-04-09 14:37:16 -04:00
|
|
|
};
|
2013-11-27 11:21:16 -05:00
|
|
|
|
2015-05-26 14:45:17 -04:00
|
|
|
Groups.internals = internals;
|
|
|
|
|
|
2015-05-26 13:17:49 -04:00
|
|
|
var isPrivilegeGroupRegex = /^cid:\d+:privileges:[\w:]+$/;
|
|
|
|
|
Groups.isPrivilegeGroup = function(groupName) {
|
|
|
|
|
return isPrivilegeGroupRegex.test(groupName);
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-26 18:33:01 -04:00
|
|
|
Groups.getEphemeralGroups = function() {
|
|
|
|
|
return ephemeralGroups;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-02 16:20:10 -04:00
|
|
|
Groups.getGroupsFromSet = function(set, uid, start, stop, callback) {
|
|
|
|
|
var method;
|
|
|
|
|
var args;
|
|
|
|
|
if (set === 'groups:visible:name') {
|
|
|
|
|
method = db.getSortedSetRangeByLex;
|
|
|
|
|
args = [set, '-', '+', start, stop - start + 1, done];
|
|
|
|
|
} else {
|
|
|
|
|
method = db.getSortedSetRevRange;
|
|
|
|
|
args = [set, start, stop, done];
|
|
|
|
|
}
|
|
|
|
|
method.apply(null, args);
|
|
|
|
|
|
|
|
|
|
function done(err, groupNames) {
|
2014-07-31 08:01:11 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2015-05-13 18:31:38 -04:00
|
|
|
|
2015-06-02 16:20:10 -04:00
|
|
|
if (set === 'groups:visible:name') {
|
|
|
|
|
groupNames = groupNames.map(function(name) {
|
|
|
|
|
return name.split(':')[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-05-14 16:13:30 -04:00
|
|
|
|
2015-02-23 15:43:32 -05:00
|
|
|
async.parallel({
|
2015-05-26 15:37:33 -04:00
|
|
|
groups: function(next) {
|
|
|
|
|
Groups.getGroupsData(groupNames, next);
|
|
|
|
|
},
|
|
|
|
|
members: function(next) {
|
|
|
|
|
Groups.getMemberUsers(groupNames, 0, 3, next);
|
2015-02-23 15:43:32 -05:00
|
|
|
}
|
|
|
|
|
}, function (err, data) {
|
2015-05-26 15:37:33 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
data.groups.forEach(function(group, index) {
|
|
|
|
|
if (!group) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-28 15:14:40 -04:00
|
|
|
Groups.escapeGroupData(group);
|
2015-05-26 15:37:33 -04:00
|
|
|
group.members = data.members[index] || [];
|
|
|
|
|
group.truncated = group.memberCount > data.members.length;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, data.groups);
|
2014-05-14 16:13:30 -04:00
|
|
|
});
|
2015-06-02 16:20:10 -04:00
|
|
|
}
|
2013-11-27 11:21:16 -05:00
|
|
|
};
|
|
|
|
|
|
2015-03-31 23:40:58 -04:00
|
|
|
Groups.getGroups = function(start, stop, callback) {
|
|
|
|
|
db.getSortedSetRevRange('groups:createtime', start, stop, callback);
|
2015-01-21 23:16:27 -05:00
|
|
|
};
|
|
|
|
|
|
2014-03-19 20:33:39 -04:00
|
|
|
Groups.get = function(groupName, options, callback) {
|
2015-05-28 14:51:01 -04:00
|
|
|
if (!groupName) {
|
|
|
|
|
return callback(new Error('[[error:invalid-group]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options.escape = options.hasOwnProperty('escape') ? options.escape : true;
|
2015-05-28 13:33:45 -04:00
|
|
|
|
2013-11-27 11:21:16 -05:00
|
|
|
async.parallel({
|
|
|
|
|
base: function (next) {
|
2015-05-28 14:51:01 -04:00
|
|
|
db.getObject('group:' + groupName, next);
|
2015-01-08 15:13:05 -05:00
|
|
|
},
|
2015-05-28 14:51:01 -04:00
|
|
|
owners: function (next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.getSetMembers('group:' + groupName + ':owners', next);
|
|
|
|
|
},
|
|
|
|
|
function(uids, next) {
|
|
|
|
|
user.getUsers(uids, options.uid, next);
|
2015-01-08 17:06:33 -05:00
|
|
|
}
|
2015-05-28 14:51:01 -04:00
|
|
|
], next);
|
2015-01-08 17:06:33 -05:00
|
|
|
},
|
2015-05-28 14:51:01 -04:00
|
|
|
members: function (next) {
|
|
|
|
|
var stop = -1;
|
|
|
|
|
if (options.truncateUserList) {
|
|
|
|
|
stop = (parseInt(options.userListCount, 10) || 4) - 1;
|
2015-01-08 15:13:05 -05:00
|
|
|
}
|
2015-05-28 14:51:01 -04:00
|
|
|
user.getUsersFromSet('group:' + groupName + ':members', options.uid, 0, stop, next);
|
2015-01-08 15:13:05 -05:00
|
|
|
},
|
2015-05-28 14:51:01 -04:00
|
|
|
pending: function (next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.getSetMembers('group:' + groupName + ':pending', next);
|
|
|
|
|
},
|
|
|
|
|
function(uids, next) {
|
|
|
|
|
user.getUsersData(uids, next);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
2015-01-08 16:50:31 -05:00
|
|
|
},
|
2015-05-28 14:51:01 -04:00
|
|
|
isMember: async.apply(Groups.isMember, options.uid, groupName),
|
|
|
|
|
isPending: async.apply(Groups.isPending, options.uid, groupName),
|
2015-02-23 16:31:18 -05:00
|
|
|
isInvited: async.apply(Groups.isInvited, options.uid, groupName),
|
2015-05-28 14:51:01 -04:00
|
|
|
isOwner: async.apply(Groups.ownership.isOwner, options.uid, groupName)
|
2013-11-27 11:21:16 -05:00
|
|
|
}, function (err, results) {
|
2015-01-18 17:18:53 -05:00
|
|
|
if (err) {
|
2013-11-27 11:21:16 -05:00
|
|
|
return callback(err);
|
2015-01-18 17:18:53 -05:00
|
|
|
} else if (!results.base) {
|
|
|
|
|
return callback(new Error('[[error:no-group]]'));
|
2013-11-27 11:21:16 -05:00
|
|
|
}
|
2013-08-28 22:06:55 -04:00
|
|
|
|
2015-01-12 21:14:00 -05:00
|
|
|
// Default image
|
|
|
|
|
if (!results.base['cover:url']) {
|
|
|
|
|
results.base['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
|
|
|
|
|
results.base['cover:position'] = '50% 50%';
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 14:51:01 -04:00
|
|
|
var ownerUids = [];
|
|
|
|
|
results.owners.forEach(function(user) {
|
|
|
|
|
if (user) {
|
|
|
|
|
user.isOwner = true;
|
|
|
|
|
ownerUids.push(user.uid.toString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
results.members = results.members.filter(function(user, index, array) {
|
|
|
|
|
return user && user.uid && ownerUids.indexOf(user.uid.toString()) === -1;
|
|
|
|
|
});
|
|
|
|
|
results.members = results.owners.concat(results.members);
|
|
|
|
|
|
2015-02-19 12:23:36 -05:00
|
|
|
plugins.fireHook('filter:parse.raw', results.base.description, function(err, descriptionParsed) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2015-05-28 15:14:40 -04:00
|
|
|
|
|
|
|
|
if (options.escape) {
|
|
|
|
|
Groups.escapeGroupData(results.base);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 12:23:36 -05:00
|
|
|
results.base.descriptionParsed = descriptionParsed;
|
2015-02-25 10:51:35 -05:00
|
|
|
results.base.userTitleEnabled = results.base.userTitleEnabled ? !!parseInt(results.base.userTitleEnabled, 10) : true;
|
2015-02-19 12:23:36 -05:00
|
|
|
results.base.createtimeISO = utils.toISOString(results.base.createtime);
|
2015-05-28 15:14:40 -04:00
|
|
|
results.base.members = results.members;
|
2015-02-19 12:23:36 -05:00
|
|
|
results.base.pending = results.pending.filter(Boolean);
|
|
|
|
|
results.base.deleted = !!parseInt(results.base.deleted, 10);
|
|
|
|
|
results.base.hidden = !!parseInt(results.base.hidden, 10);
|
|
|
|
|
results.base.system = !!parseInt(results.base.system, 10);
|
|
|
|
|
results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true;
|
|
|
|
|
results.base.isMember = results.isMember;
|
|
|
|
|
results.base.isPending = results.isPending;
|
2015-02-23 16:31:18 -05:00
|
|
|
results.base.isInvited = results.isInvited;
|
2015-02-19 12:23:36 -05:00
|
|
|
results.base.isOwner = results.isOwner;
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:group.get', {group: results.base}, function(err, data) {
|
|
|
|
|
callback(err, data ? data.group : null);
|
2015-02-26 12:22:48 -05:00
|
|
|
});
|
|
|
|
|
});
|
2013-11-27 11:21:16 -05:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-28 15:14:40 -04:00
|
|
|
Groups.escapeGroupData = function(group) {
|
|
|
|
|
if (group) {
|
2015-06-28 14:04:11 -04:00
|
|
|
group.nameEncoded = encodeURIComponent(group.name);
|
2015-05-28 15:14:40 -04:00
|
|
|
group.name = validator.escape(group.name);
|
|
|
|
|
group.description = validator.escape(group.description);
|
2015-06-22 13:10:18 -04:00
|
|
|
group.userTitle = validator.escape(group.userTitle) || group.name;
|
2015-05-28 15:14:40 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-18 17:18:53 -05:00
|
|
|
Groups.getByGroupslug = function(slug, options, callback) {
|
|
|
|
|
db.getObjectField('groupslug:groupname', slug, function(err, groupName) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
} else if (!groupName) {
|
|
|
|
|
return callback(new Error('[[error:no-group]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Groups.get.call(Groups, groupName, options, callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-25 20:53:57 -05:00
|
|
|
Groups.getGroupNameByGroupSlug = function(slug, callback) {
|
|
|
|
|
db.getObjectField('groupslug:groupname', slug, callback);
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-12 20:34:15 -05:00
|
|
|
Groups.getGroupFields = function(groupName, fields, callback) {
|
2015-03-25 15:42:15 -04:00
|
|
|
Groups.getMultipleGroupFields([groupName], fields, function(err, groups) {
|
|
|
|
|
callback(err, groups ? groups[0] : null);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.getMultipleGroupFields = function(groups, fields, callback) {
|
|
|
|
|
db.getObjectsFields(groups.map(function(group) {
|
|
|
|
|
return 'group:' + group;
|
|
|
|
|
}), fields, callback);
|
2015-01-12 20:34:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.setGroupField = function(groupName, field, value, callback) {
|
2015-05-28 15:27:55 -04:00
|
|
|
db.setObjectField('group:' + groupName, field, value, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
plugins.fireHook('action:group.set', {field: field, value: value, type: 'set'});
|
2015-05-29 00:40:59 -04:00
|
|
|
callback();
|
2015-05-28 15:27:55 -04:00
|
|
|
});
|
2015-01-12 20:34:15 -05:00
|
|
|
};
|
|
|
|
|
|
2015-01-08 16:50:31 -05:00
|
|
|
Groups.isPrivate = function(groupName, callback) {
|
|
|
|
|
db.getObjectField('group:' + groupName, 'private', function(err, isPrivate) {
|
2015-01-09 10:33:54 -05:00
|
|
|
isPrivate = isPrivate || isPrivate === null;
|
|
|
|
|
|
|
|
|
|
if (typeof isPrivate === 'string') {
|
|
|
|
|
isPrivate = (isPrivate === '0' ? false : true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(err, isPrivate); // Private, if not set at all
|
2015-01-08 16:50:31 -05:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-23 14:54:48 -05:00
|
|
|
Groups.isHidden = function(groupName, callback) {
|
|
|
|
|
Groups.getGroupFields(groupName, ['hidden'], function(err, values) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.warn('[groups.isHidden] Could not determine group hidden state (group: ' + groupName + ')');
|
|
|
|
|
return callback(null, true); // Default true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, parseInt(values.hidden, 10));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-27 11:21:16 -05:00
|
|
|
Groups.exists = function(name, callback) {
|
2014-07-29 21:51:46 -04:00
|
|
|
if (Array.isArray(name)) {
|
2015-01-19 10:46:14 -05:00
|
|
|
var slugs = name.map(function(groupName) {
|
|
|
|
|
return utils.slugify(groupName);
|
|
|
|
|
});
|
|
|
|
|
async.parallel([
|
2015-02-18 15:33:21 -05:00
|
|
|
function(next) {
|
|
|
|
|
callback(null, slugs.map(function(slug) {
|
|
|
|
|
return ephemeralGroups.indexOf(slug) !== -1;
|
|
|
|
|
}));
|
|
|
|
|
},
|
2015-01-26 16:48:39 -05:00
|
|
|
async.apply(db.isSortedSetMembers, 'groups:createtime', name)
|
2015-01-19 10:46:14 -05:00
|
|
|
], function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 15:33:21 -05:00
|
|
|
callback(null, results.map(function(result) {
|
2015-03-19 22:59:12 -04:00
|
|
|
return result[0] || result[1];
|
2015-01-19 10:46:14 -05:00
|
|
|
}));
|
|
|
|
|
});
|
2014-07-29 21:51:46 -04:00
|
|
|
} else {
|
2015-01-19 10:46:14 -05:00
|
|
|
var slug = utils.slugify(name);
|
|
|
|
|
async.parallel([
|
2015-02-18 15:33:21 -05:00
|
|
|
function(next) {
|
|
|
|
|
next(null, ephemeralGroups.indexOf(slug) !== -1);
|
|
|
|
|
},
|
2015-01-21 22:48:22 -05:00
|
|
|
async.apply(db.isSortedSetMember, 'groups:createtime', name)
|
2015-01-19 10:46:14 -05:00
|
|
|
], function(err, results) {
|
2015-03-19 22:59:12 -04:00
|
|
|
callback(err, !err ? (results[0] || results[1]) : null);
|
2015-01-19 10:46:14 -05:00
|
|
|
});
|
2014-07-29 21:51:46 -04:00
|
|
|
}
|
2013-11-27 11:21:16 -05:00
|
|
|
};
|
|
|
|
|
|
2015-02-06 20:42:20 -05:00
|
|
|
Groups.existsBySlug = function(slug, callback) {
|
2015-03-19 22:59:12 -04:00
|
|
|
if (Array.isArray(slug)) {
|
2015-06-24 17:15:58 -04:00
|
|
|
db.isObjectFields('groupslug:groupname', slug, callback);
|
2015-03-19 22:59:12 -04:00
|
|
|
} else {
|
|
|
|
|
db.isObjectField('groupslug:groupname', slug, callback);
|
|
|
|
|
}
|
2015-02-06 20:42:20 -05:00
|
|
|
};
|
|
|
|
|
|
2015-02-23 14:54:48 -05:00
|
|
|
Groups.getLatestMemberPosts = function(groupName, max, uid, callback) {
|
2014-11-30 12:52:16 -05:00
|
|
|
async.waterfall([
|
2015-02-23 14:54:48 -05:00
|
|
|
async.apply(Groups.getMembers, groupName, 0, -1),
|
2014-11-30 12:52:16 -05:00
|
|
|
function(uids, next) {
|
|
|
|
|
if (!Array.isArray(uids) || !uids.length) {
|
|
|
|
|
return callback(null, []);
|
2014-06-18 19:59:58 -04:00
|
|
|
}
|
2014-11-30 12:52:16 -05:00
|
|
|
var keys = uids.map(function(uid) {
|
|
|
|
|
return 'uid:' + uid + ':posts';
|
|
|
|
|
});
|
|
|
|
|
db.getSortedSetRevUnion(keys, 0, max - 1, next);
|
|
|
|
|
},
|
|
|
|
|
function(pids, next) {
|
|
|
|
|
privileges.posts.filter('read', pids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function(pids, next) {
|
|
|
|
|
posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
2014-06-12 18:53:58 -04:00
|
|
|
};
|
|
|
|
|
|
2015-02-20 14:20:49 -05:00
|
|
|
Groups.getGroupsData = function(groupNames, callback) {
|
|
|
|
|
if (!Array.isArray(groupNames) || !groupNames.length) {
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
var keys = groupNames.map(function(groupName) {
|
|
|
|
|
return 'group:' + groupName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
db.getObjects(keys, function(err, groupData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2015-05-28 15:52:00 -04:00
|
|
|
groupData.forEach(function(group) {
|
2015-02-20 14:20:49 -05:00
|
|
|
if (group) {
|
2015-02-25 10:51:35 -05:00
|
|
|
group.userTitle = validator.escape(group.userTitle) || validator.escape(group.name);
|
|
|
|
|
group.userTitleEnabled = group.userTitleEnabled ? parseInt(group.userTitleEnabled, 10) === 1 : true;
|
2015-02-20 14:20:49 -05:00
|
|
|
group.labelColor = group.labelColor || '#000000';
|
|
|
|
|
group.createtimeISO = utils.toISOString(group.createtime);
|
|
|
|
|
group.hidden = parseInt(group.hidden, 10) === 1;
|
2015-05-26 15:37:33 -04:00
|
|
|
group.system = parseInt(group.system, 10) === 1;
|
|
|
|
|
group.private = parseInt(group.private, 10) === 1;
|
2015-02-20 14:20:49 -05:00
|
|
|
if (!group['cover:url']) {
|
|
|
|
|
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
|
|
|
|
|
group['cover:position'] = '50% 50%';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-02-26 12:22:48 -05:00
|
|
|
|
2015-02-20 14:20:49 -05:00
|
|
|
plugins.fireHook('filter:groups.get', {groups: groupData}, function(err, data) {
|
2015-02-26 12:22:48 -05:00
|
|
|
callback(err, data ? data.groups : null);
|
|
|
|
|
});
|
2015-02-20 14:20:49 -05:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-09 02:07:03 -04:00
|
|
|
Groups.getUserGroups = function(uids, callback) {
|
2015-06-04 14:16:00 -04:00
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.getSortedSetRevRange('groups:visible:createtime', 0, -1, next);
|
|
|
|
|
},
|
|
|
|
|
function(groupNames, next) {
|
|
|
|
|
var groupSets = groupNames.map(function(name) {
|
|
|
|
|
return 'group:' + name + ':members';
|
|
|
|
|
});
|
2014-06-12 18:53:58 -04:00
|
|
|
|
2015-06-04 14:16:00 -04:00
|
|
|
async.map(uids, function(uid, next) {
|
2015-01-30 22:38:42 -05:00
|
|
|
db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
2014-06-12 18:53:58 -04:00
|
|
|
}
|
|
|
|
|
|
2015-01-30 22:38:42 -05:00
|
|
|
var memberOf = [];
|
|
|
|
|
isMembers.forEach(function(isMember, index) {
|
|
|
|
|
if (isMember) {
|
2015-06-04 14:16:00 -04:00
|
|
|
memberOf.push(groupNames[index]);
|
2014-08-09 02:07:03 -04:00
|
|
|
}
|
2015-01-30 16:24:57 -05:00
|
|
|
});
|
2015-01-30 22:38:42 -05:00
|
|
|
|
2015-05-19 00:06:37 -04:00
|
|
|
Groups.getGroupsData(memberOf, next);
|
2015-01-30 22:38:42 -05:00
|
|
|
});
|
2015-06-04 14:16:00 -04:00
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
2014-06-18 19:59:58 -04:00
|
|
|
};
|
2015-06-04 14:16:00 -04:00
|
|
|
|
2013-11-27 11:21:16 -05:00
|
|
|
}(module.exports));
|