|
|
|
@ -299,7 +299,7 @@ var async = require('async'),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.getMemberCount = function(groupName, callback) {
|
|
|
|
|
db.sortedSetCard('group:' + groupName + ':members', callback);
|
|
|
|
|
db.getObjectField('group:' + groupName, 'memberCount', callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.isMemberOfGroupList = function(uid, groupListKey, callback) {
|
|
|
|
@ -611,29 +611,45 @@ var async = require('async'),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.join = function(groupName, uid, callback) {
|
|
|
|
|
callback = callback || function() {};
|
|
|
|
|
|
|
|
|
|
Groups.exists(groupName, function(err, exists) {
|
|
|
|
|
if (exists) {
|
|
|
|
|
function join() {
|
|
|
|
|
var tasks = [
|
|
|
|
|
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid)
|
|
|
|
|
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid),
|
|
|
|
|
async.apply(db.incrObjectField, 'group:' + groupName, 'memberCount')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
user.isAdministrator(uid, function(err, isAdmin) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
user.isAdministrator(uid, next);
|
|
|
|
|
},
|
|
|
|
|
function(isAdmin, next) {
|
|
|
|
|
if (isAdmin) {
|
|
|
|
|
tasks.push(async.apply(db.setAdd, 'group:' + groupName + ':owners', uid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel(tasks, function(err) {
|
|
|
|
|
async.parallel(tasks, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
plugins.fireHook('action:group.join', {
|
|
|
|
|
groupName: groupName,
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback = callback || function() {};
|
|
|
|
|
|
|
|
|
|
Groups.exists(groupName, function(err, exists) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
|
return join();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Groups.create({
|
|
|
|
|
name: groupName,
|
|
|
|
|
description: '',
|
|
|
|
@ -643,14 +659,8 @@ var async = require('async'),
|
|
|
|
|
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.sortedSetAdd('group:' + groupName + ':members', Date.now(), uid, callback);
|
|
|
|
|
plugins.fireHook('action:group.join', {
|
|
|
|
|
groupName: groupName,
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
join();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -693,7 +703,8 @@ var async = require('async'),
|
|
|
|
|
|
|
|
|
|
var tasks = [
|
|
|
|
|
async.apply(db.sortedSetRemove, 'group:' + groupName + ':members', uid),
|
|
|
|
|
async.apply(db.setRemove, 'group:' + groupName + ':owners', uid)
|
|
|
|
|
async.apply(db.setRemove, 'group:' + groupName + ':owners', uid),
|
|
|
|
|
async.apply(db.decrObjectField, 'group:' + groupName, 'memberCount')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
async.parallel(tasks, function(err) {
|
|
|
|
@ -715,7 +726,7 @@ var async = require('async'),
|
|
|
|
|
if (group.hidden && group.memberCount === 0) {
|
|
|
|
|
Groups.destroy(groupName, callback);
|
|
|
|
|
} else {
|
|
|
|
|
return callback();
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -781,25 +792,11 @@ 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;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.map(groupData, function(groupObj, next) {
|
|
|
|
|
Groups.getMemberCount(groupObj.name, function(err, memberCount) {
|
|
|
|
|
if (err) { return next(err); }
|
|
|
|
|
|
|
|
|
|
groupObj.memberCount = memberCount;
|
|
|
|
|
next(err, groupObj);
|
|
|
|
|
});
|
|
|
|
|
}, function(err, groupData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var groupSets = groupData.map(function(group) {
|
|
|
|
|
group.labelColor = group.labelColor || '#000000';
|
|
|
|
|
group.createtimeISO = utils.toISOString(group.createtime);
|
|
|
|
|
|
|
|
|
|
if (!group['cover:url']) {
|
|
|
|
|
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
|
|
|
|
@ -827,7 +824,6 @@ var async = require('async'),
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Groups.updateCoverPosition = function(groupName, position, callback) {
|
|
|
|
|