This commit is contained in:
barisusakli
2015-06-09 17:47:02 -04:00
parent a6cfdc7508
commit 2880a77a9f
5 changed files with 43 additions and 0 deletions

View File

@@ -337,4 +337,11 @@ module.exports = function(Groups) {
}
db.isSetMember('group:' + groupName + ':pending', uid, callback);
};
Groups.getPending = function(groupName, callback) {
if (!groupName) {
return callback(null, []);
}
db.getSetMembers('group:' + groupName + ':pending', callback);
};
};

View File

@@ -102,6 +102,37 @@ SocketGroups.reject = function(socket, data, callback) {
});
};
SocketGroups.acceptAll = function(socket, data, callback) {
acceptRejectAll('accept', socket, data, callback);
};
SocketGroups.rejectAll = function(socket, data, callback) {
acceptRejectAll('reject', socket, data, callback);
};
function acceptRejectAll(type, socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
if (err || !isOwner) {
return callback(err || new Error('[[error:no-privileges]]'));
}
async.waterfall([
function(next) {
groups.getPending(data.groupName, next);
},
function(uids, next) {
var method = type === 'accept' ? groups.acceptMembership : groups.rejectMembership;
async.each(uids, function(uid, next) {
method(data.groupName, uid, next);
}, next);
}
], callback);
});
}
SocketGroups.acceptInvite = function(socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));