Added party sync and request sync events (#8223)

* Added party sync and request sync events

* Changed party member sync to be handled locally

* Optimized assignment to only use member variables

* Removed party sync event
This commit is contained in:
Keith Holliday
2016-11-17 13:10:33 -06:00
committed by Matteo Pagliazzi
parent 3ea7b72024
commit 25c6691793
2 changed files with 12 additions and 0 deletions

View File

@@ -14,6 +14,10 @@ habitrpg.controller('NotificationCtrl',
if (after == before) return; if (after == before) return;
if (User.user.stats.lvl == 0) return; if (User.user.stats.lvl == 0) return;
Notification.hp(after - before, 'hp'); Notification.hp(after - before, 'hp');
$rootScope.$broadcast('syncPartyRequest', {
type: 'user_update',
user: User.user,
}); // Sync party to update members
if (after < 0) $rootScope.playSound('Minus_Habit'); if (after < 0) $rootScope.playSound('Minus_Habit');
}); });

View File

@@ -107,6 +107,14 @@ angular.module('habitrpg')
}); });
}; };
$rootScope.$on('syncPartyRequest', function (event, options) {
if (options.type === 'user_update') {
var index = _.findIndex(data.party.members, function(user) { return user._id === options.user._id; });
var memberToUpdate = data.party.members[index];
_.assign(memberToUpdate, _.pick(User.user, _.keys(memberToUpdate)));
}
});
//On page load, multiple controller request the party. //On page load, multiple controller request the party.
//So, we cache the promise until the first result is returned //So, we cache the promise until the first result is returned
var _cachedPartyPromise; var _cachedPartyPromise;