Change condition scope to fix updating for public guilds with a member count of 1
This commit is contained in:
@@ -574,30 +574,31 @@ api.leave = function(req, res, next) {
|
||||
}
|
||||
update['$inc'] = {memberCount: -1};
|
||||
Group.update({_id:group._id}, update, cb);
|
||||
} else if (group.members.length === 1) {
|
||||
//We don't delete public groups when they are empty
|
||||
if (group.privacy === 'private' || group.type === 'party') {
|
||||
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) {
|
||||
Group.remove({_id:group._id}, cb2);
|
||||
},
|
||||
], cb);
|
||||
}
|
||||
}
|
||||
if (group.members.length === 1 && (group.privacy === 'private' || group.type === 'party') ) {
|
||||
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) {
|
||||
Group.remove({_id:group._id}, cb2);
|
||||
},
|
||||
], cb);
|
||||
} else {
|
||||
update['$inc'] = {memberCount: -1};
|
||||
Group.update({_id:group._id}, update, cb);
|
||||
}
|
||||
}
|
||||
],function(err){
|
||||
|
||||
Reference in New Issue
Block a user