diff --git a/common/locales/en/groups.json b/common/locales/en/groups.json index cc9bcf9cd7..b3eeaa54b8 100644 --- a/common/locales/en/groups.json +++ b/common/locales/en/groups.json @@ -36,7 +36,7 @@ "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", - "loadingNewParty": "Your new party is loading. Please wait...", + "loadingNewParty": "Your party is loading. Please wait...", "newMsg": "New message in \"<%= name %>\"", "chat": "Chat", "sendChat": "Send Chat", diff --git a/test/spec/controllers/partyCtrlSpec.js b/test/spec/controllers/partyCtrlSpec.js index 00d3e676c5..433bd6d0fe 100644 --- a/test/spec/controllers/partyCtrlSpec.js +++ b/test/spec/controllers/partyCtrlSpec.js @@ -48,12 +48,15 @@ describe("Party Controller", function() { inject(function(_$state_) { var state = _$state_; sandbox.stub(state, 'is').returns(true); + var syncParty = sinon.stub(groups.Group, 'syncParty') syncParty.returns(Promise.resolve(groupResponse)); + + var froceSyncParty = sinon.stub(groups, 'party') + froceSyncParty.returns(Promise.resolve(groupResponse)); + $controller('PartyCtrl', { $scope: scope, $state: state, User: User }); - // @TODO: I have update the party ctrl to sync the user whenever it is called rather than only on the party page - // Since I have cached the promise, this should not be a performance issue, but let's keep this test here in case anything breaks. - // expect(state.is).to.be.calledOnce; // ensure initialization worked as desired + expect(state.is).to.be.calledOnce; }); }; diff --git a/website/client/js/controllers/inviteToGroupCtrl.js b/website/client/js/controllers/inviteToGroupCtrl.js index a986cd768c..a4b8495a27 100644 --- a/website/client/js/controllers/inviteToGroupCtrl.js +++ b/website/client/js/controllers/inviteToGroupCtrl.js @@ -48,14 +48,13 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', '$rootScope', 'User', 'Group .then(function() { Notification.text(window.env.t('invitationsSent')); _resetInvitees(); - var redirectTo = '/#/options/groups/' if ($scope.group.type === 'party') { - redirectTo += 'party'; - } else { - redirectTo += ('guilds/' + $scope.group._id); + Groups.removePartyCache(); + $rootScope.$state.go('options.social.party'); + return; } - $rootScope.hardRedirect(redirectTo); + $rootScope.hardRedirect('/#/options/groups/guilds/' + $scope.group._id); }, function(){ _resetInvitees(); }); diff --git a/website/client/js/controllers/partyCtrl.js b/website/client/js/controllers/partyCtrl.js index 64070734bf..ffc810251f 100644 --- a/website/client/js/controllers/partyCtrl.js +++ b/website/client/js/controllers/partyCtrl.js @@ -7,17 +7,25 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User',' $scope.type = 'party'; $scope.text = window.env.t('party'); + $scope.group = {loadingParty: true} $scope.inviteOrStartParty = Groups.inviteOrStartParty; $scope.loadWidgets = Social.loadWidgets; - Groups.Group.syncParty() - .then(function successCallback(group) { - $rootScope.party = $scope.group = group; - checkForNotifications(); - }, function errorCallback(response) { - $rootScope.party = $scope.group = $scope.newGroup = { type: 'party' }; - }); + function handlePartyResponse (group) { + $rootScope.party = $scope.group = group; + checkForNotifications(); + } + + function handlePartyError (response) { + $rootScope.party = $scope.group = $scope.newGroup = { type: 'party' }; + } + + if ($state.is('options.social.party') && $rootScope.party && $rootScope.party.id) { + Groups.party(true).then(handlePartyResponse, handlePartyError); + } else { + Groups.Group.syncParty().then(handlePartyResponse, handlePartyError); + } function checkForNotifications () { // Checks if user's party has reached 2 players for the first time. @@ -40,6 +48,8 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User',' } $scope.create = function(group) { + group.loadingParty = true; + if (!group.name) group.name = env.t('possessiveParty', {name: User.user.profile.name}); Groups.Group.create(group) .then(function(response) { @@ -134,7 +144,7 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User',' Groups.Group.leave(Groups.data.party._id, false) .then(function() { $rootScope.party = $scope.group = { - loadingNewParty: true + loadingParty: true }; $scope.join({ id: newPartyId, name: newPartyName }); }); diff --git a/website/client/js/services/groupServices.js b/website/client/js/services/groupServices.js index 1411e5e2cb..c3f74ca0f8 100644 --- a/website/client/js/services/groupServices.js +++ b/website/client/js/services/groupServices.js @@ -110,6 +110,7 @@ angular.module('habitrpg') //On page load, multiple controller request the party. //So, we cache the promise until the first result is returned var _cachedPartyPromise; + function party (forceUpdate) { if (_cachedPartyPromise && !forceUpdate) return _cachedPartyPromise.promise; _cachedPartyPromise = $q.defer(); @@ -150,6 +151,10 @@ angular.module('habitrpg') return _cachedPartyPromise.promise; } + function removePartyCache () { + _cachedPartyPromise = null; + } + function publicGuilds () { var deferred = $q.defer(); @@ -207,8 +212,10 @@ angular.module('habitrpg') function inviteOrStartParty (group) { Analytics.track({'hitType':'event','eventCategory':'button','eventAction':'click','eventLabel':'Invite Friends'}); + if (group.type === "party" || $location.$$path === "/options/groups/party") { group.type = 'party'; + $rootScope.openModal('invite-party', { controller:'InviteToGroupCtrl', resolve: { @@ -227,6 +234,7 @@ angular.module('habitrpg') myGuilds: myGuilds, tavern: tavern, inviteOrStartParty: inviteOrStartParty, + removePartyCache: removePartyCache, data: data, Group: Group, diff --git a/website/views/options/social/party.jade b/website/views/options/social/party.jade index 6f0229152d..ed3fe9189b 100644 --- a/website/views/options/social/party.jade +++ b/website/views/options/social/party.jade @@ -1,13 +1,13 @@ include ../../shared/avatar/generated_avatar script(type='text/ng-template', id='partials/options.social.party.html') - div(ng-if='group.loadingNewParty') + div(ng-if='group.loadingParty') include ./party/loading-new-party div(ng-if='group._id') include ./party/leave-party-and-join-another include ./group - div(ng-if='!group._id && !group.loadingNewParty') + div(ng-if='!group._id && !group.loadingParty') include ./party/party-invitation include ./party/start-a-party diff --git a/website/views/options/social/party/start-a-party.jade b/website/views/options/social/party/start-a-party.jade index 49d9768b2d..b6946ed0aa 100644 --- a/website/views/options/social/party/start-a-party.jade +++ b/website/views/options/social/party/start-a-party.jade @@ -19,5 +19,5 @@ .row.row-margin .btn.btn-primary(ng-click='inviteOrStartParty(group)')=env.t('inviteFriendsNow') - .btn.btn-default(ng-click='create(newGroup); group.loadingNewParty = true')=env.t('inviteFriendsLater') + .btn.btn-default(ng-click='create(newGroup)')=env.t('inviteFriendsLater') .btn.btn-default(ng-click='openModal("user-id",{track:"Join Existing Party"})')=env.t('joinExistingParty')