Add feature to join new party if user is in a party of one

This commit is contained in:
Blade Barringer
2015-08-22 12:19:37 -05:00
parent 8c66714e5f
commit 93f02363e5
6 changed files with 61 additions and 3 deletions

View File

@@ -30,6 +30,9 @@
"invite": "Invite", "invite": "Invite",
"leave": "Leave", "leave": "Leave",
"invitedTo": "Invited to <%= name %>", "invitedTo": "Invited to <%= name %>",
"invitedToNewParty": "You were invited to join a party! Do you want to leave this party and join <%= partyName %>?",
"joinNewParty": "Join New Party",
"declineInvitation": "Decline Invitation",
"newMsg": "New message in \"<%= name %>\"", "newMsg": "New message in \"<%= name %>\"",
"chat": "Chat", "chat": "Chat",
"sendChat": "Send Chat", "sendChat": "Send Chat",

View File

@@ -172,4 +172,42 @@ describe("Party Controller", function() {
expect(rootScope.$state.go).to.be.calledWith('options.inventory.quests'); expect(rootScope.$state.go).to.be.calledWith('options.inventory.quests');
}); });
}); });
describe('#leaveOldPartyAndJoinNewParty', function() {
beforeEach(function() {
sandbox.stub(scope, 'join');
sandbox.stub(groups.Group, 'leave').yields();
sandbox.stub(groups, 'party').returns({
_id: 'old-party'
});
sandbox.stub(window, 'confirm').returns(true);
});
it('does nothing if user declines confirmation', function() {
window.confirm.returns(false);
scope.leaveOldPartyAndJoinNewParty('some-id', 'some-name');
expect(groups.Group.leave).to.not.be.called;
})
it('leaves user\'s current party', function() {
scope.leaveOldPartyAndJoinNewParty('some-id', 'some-name');
expect(groups.Group.leave).to.be.calledOnce;
expect(groups.Group.leave).to.be.calledWith({
gid: 'old-party',
keep: false
});
});
it('joins the new party', function() {
scope.leaveOldPartyAndJoinNewParty('some-id', 'some-name');
expect(scope.join).to.be.calledOnce;
expect(scope.join).to.be.calledWith({
id: 'some-id',
name: 'some-name'
});
});
});
}); });

View File

@@ -88,8 +88,15 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
} }
}; };
$scope.leaveOldPartyAndJoinNewParty = function(newPartyId, newPartyName) {
if (confirm('Are you sure you want to delete your party and join ' + newPartyName + '?')) {
Groups.Group.leave({gid: Groups.party()._id, keep:false}, undefined, function() {
$scope.join({ id: newPartyId, name: newPartyName });
});
}
}
$scope.reject = function(){ $scope.reject = function(){
//User.user.invitations.party = undefined;
User.set({'invitations.party':{}}); User.set({'invitations.party':{}});
} }

View File

@@ -577,8 +577,9 @@ var inviteByUUIDs = function(uuids, group, req, res, next){
return cb({code:400,err:"User already pending invitation."}); return cb({code:400,err:"User already pending invitation."});
Group.find({type:'party', members:{$in:[uuid]}}, function(err, groups){ Group.find({type:'party', members:{$in:[uuid]}}, function(err, groups){
if (err) return cb(err); if (err) return cb(err);
if (!_.isEmpty(groups)) if (!_.isEmpty(groups) && groups[0].members.length > 1) {
return cb({code:400,err:"User already in a party."}) return cb({code:400, err:"User already in a party."})
}
sendInvite(); sendInvite();
}); });
} }

View File

@@ -0,0 +1,8 @@
- var newParty = 'User.user.invitations.party'
.containter-fulid(ng-if='#{newParty}.id && party._id')
.row.text-center
.col-sm-6.col-sm-offset-3.alert.alert-warning
p {{::env.t('invitedToNewParty', { partyName: #{newParty}.name })}}
p
button.btn.btn-success(ng-click='leaveOldPartyAndJoinNewParty(#{newParty}.id, #{newParty}.name)')=env.t('joinNewParty')
button.btn.btn-default(ng-click='reject()')=env.t('declineInvitation')

View File

@@ -2,6 +2,7 @@ include ../../shared/avatar/generated_avatar
script(type='text/ng-template', id='partials/options.social.party.html') script(type='text/ng-template', id='partials/options.social.party.html')
div(ng-if='group._id') div(ng-if='group._id')
include ./leave-party-and-join-another
include ./group include ./group
div(ng-if='!group._id') div(ng-if='!group._id')
div(ng-show='user.invitations.party.id').container-fluid div(ng-show='user.invitations.party.id').container-fluid