mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
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:
committed by
Matteo Pagliazzi
parent
3ea7b72024
commit
25c6691793
@@ -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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user