[#1516] fixes to handling user.invitations.guilds - both accept & reject

This commit is contained in:
Tyler Renelle
2013-09-11 17:16:23 -04:00
parent 48c078a6ea
commit 2f8c9fea78
3 changed files with 9 additions and 3 deletions

View File

@@ -128,6 +128,13 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
}
$scope.join = function(group){
// If we're accepting an invitation, we don't have the actual group object, but a faux group object (for performance
// purposes) {id, name}. Let's trick ngResource into thinking we have a group, so we can call the same $join
// function (server calls .attachGroup(), which finds group by _id and handles this properly)
if (group.id && !group._id) {
group = new Groups.Group({_id:group.id});
}
group.$join(function(saved){
//$scope.groups.guilds.push(saved);
alert('Joined guild, refresh page to see changes')

View File

@@ -218,7 +218,7 @@ api.join = function(req, res, next) {
}
else if (group.type == 'guild' && user.invitations && user.invitations.guilds) {
var i = _.findIndex(user.invitations.guilds, {id:group._id});
if (~i) user.invitations.guilds.slice(i,1);
if (~i) user.invitations.guilds.splice(i,1);
user.save();
}
@@ -273,7 +273,6 @@ api.invite = function(req, res, next) {
function sendInvite (){
if(group.type === 'guild'){
if(!invite.invitations.guilds) invite.invitations.guilds = [] //necessary
invite.invitations.guilds.push({id: group._id, name: group.name});
}else{
//req.body.type in 'guild', 'party'

View File

@@ -87,7 +87,7 @@ var UserSchema = new Schema({
/* FIXME remove?*/
invitations: {
guilds: Array,
guilds: {type: Array, 'default': []},
party: Schema.Types.Mixed
},
items: {