Merged changes to firebase branch

This commit is contained in:
TheHollidayInn
2015-09-06 16:58:44 -05:00
parent b839c0cd0c
commit 82a3ca8a4d
2 changed files with 27 additions and 98 deletions

View File

@@ -359,7 +359,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
var group = this;
var groupWasRemoved = false;
async.parallel([
// Remove user from group challenges
function(cb){
@@ -404,11 +404,29 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
group.type === 'party' ||
(group.type === 'guild' && group.privacy === 'private')
)){
// TODO remove invitations to this group
groupWasRemoved = true;
Group.remove({
_id: group._id
}, cb);
async.waterfall([
function(cb2) {
User.find({
'invitations.guilds.id': group._id
}, cb2);
},
function(users, cb2) {
if (users) {
users.forEach(function (user, index, array) {
var i = _.findIndex(user.invitations.guilds, {id: group._id});
user.invitations.guilds.splice(i, 1);
user.save();
});
}
cb2();
},
function(cb2) {
groupWasRemoved = true;
Group.remove({
_id: group._id
}, cb2);
},
], cb);
}else{ // otherwise just remove a member
var update = {$pull: {members: user._id}};
@@ -468,4 +486,4 @@ Group.count({_id: 'habitrpg'}, function(err, ct){
type: 'guild',
privacy: 'public'
}).save();
});
});