mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
[#1516] fixes to handling user.invitations.guilds - both accept & reject
This commit is contained in:
@@ -128,6 +128,13 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.join = function(group){
|
$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){
|
group.$join(function(saved){
|
||||||
//$scope.groups.guilds.push(saved);
|
//$scope.groups.guilds.push(saved);
|
||||||
alert('Joined guild, refresh page to see changes')
|
alert('Joined guild, refresh page to see changes')
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ api.join = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
else if (group.type == 'guild' && user.invitations && user.invitations.guilds) {
|
else if (group.type == 'guild' && user.invitations && user.invitations.guilds) {
|
||||||
var i = _.findIndex(user.invitations.guilds, {id:group._id});
|
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();
|
user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +273,6 @@ api.invite = function(req, res, next) {
|
|||||||
|
|
||||||
function sendInvite (){
|
function sendInvite (){
|
||||||
if(group.type === 'guild'){
|
if(group.type === 'guild'){
|
||||||
if(!invite.invitations.guilds) invite.invitations.guilds = [] //necessary
|
|
||||||
invite.invitations.guilds.push({id: group._id, name: group.name});
|
invite.invitations.guilds.push({id: group._id, name: group.name});
|
||||||
}else{
|
}else{
|
||||||
//req.body.type in 'guild', 'party'
|
//req.body.type in 'guild', 'party'
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ var UserSchema = new Schema({
|
|||||||
/* FIXME remove?*/
|
/* FIXME remove?*/
|
||||||
|
|
||||||
invitations: {
|
invitations: {
|
||||||
guilds: Array,
|
guilds: {type: Array, 'default': []},
|
||||||
party: Schema.Types.Mixed
|
party: Schema.Types.Mixed
|
||||||
},
|
},
|
||||||
items: {
|
items: {
|
||||||
|
|||||||
Reference in New Issue
Block a user