mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Remove localstorage and add notifications (#7588)
* move remaining files frm /common/script/public to website/public * remove localstorage * add back noscript template and put all javascript in the footer * fixes client side tests * remove double quotes where possible * simplify jade code and add tests for buildManifest * loading page with logo and spinner * better loading screen in landscape mode * icon on top of text logo * wip: user.notifications * notifications: simpler and working code * finish implementing notifications * correct loading screen css and re-inline images * add tests for user notifications * split User model in multiple files * remove old comment about missing .catch() * correctly setup hooks and methods for User model. Cleanup localstorage * include UserNotificationsService in static page js and split loading-screen css in its own file * add cron notification and misc fixes * remove console.log * fix tests * fix multiple notifications
This commit is contained in:
@@ -23,17 +23,6 @@ habitrpg.controller('NotificationCtrl',
|
||||
Notification.exp(after - before);
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.achievements', function(){
|
||||
$rootScope.playSound('Achievement_Unlocked');
|
||||
}, true);
|
||||
|
||||
$rootScope.$watch('user.achievements.challenges.length', function(after, before) {
|
||||
if (after === before) return;
|
||||
if (after > before) {
|
||||
$rootScope.openModal('wonChallenge', {controller: 'UserCtrl', size: 'sm'});
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.stats.gp', function(after, before) {
|
||||
if (after == before) return;
|
||||
if (User.user.stats.lvl == 0) return;
|
||||
@@ -82,35 +71,89 @@ habitrpg.controller('NotificationCtrl',
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.achievements.streak', function(after, before){
|
||||
if(before == undefined || after <= before) return;
|
||||
Notification.streak(User.user.achievements.streak);
|
||||
$rootScope.playSound('Achievement_Unlocked');
|
||||
if (!User.user.preferences.suppressModals.streak) {
|
||||
$rootScope.openModal('achievements/streak', {controller:'UserCtrl'});
|
||||
}
|
||||
// Avoid showing the same notiication more than once
|
||||
var lastShownNotifications = [];
|
||||
|
||||
function handleUserNotifications (after) {
|
||||
if (!after || after.length === 0) return;
|
||||
|
||||
after.forEach(function (notification) {
|
||||
if (lastShownNotifications.indexOf(notification.id) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastShownNotifications.push(notification.id);
|
||||
if (lastShownNotifications.length > 10) {
|
||||
lastShownNotifications.splice(0, 9);
|
||||
}
|
||||
|
||||
var markAsRead = true;
|
||||
|
||||
switch (notification.type) {
|
||||
case 'DROPS_ENABLED':
|
||||
$rootScope.openModal('dropsEnabled');
|
||||
break;
|
||||
case 'REBIRTH_ENABLED':
|
||||
$rootScope.openModal('rebirthEnabled');
|
||||
break;
|
||||
case 'WON_CHALLENGE':
|
||||
$rootScope.openModal('wonChallenge', {controller: 'UserCtrl', size: 'sm'});
|
||||
break;
|
||||
case 'STREAK_ACHIEVEMENT':
|
||||
Notification.streak(User.user.achievements.streak);
|
||||
$rootScope.playSound('Achievement_Unlocked');
|
||||
if (!User.user.preferences.suppressModals.streak) {
|
||||
$rootScope.openModal('achievements/streak', {controller:'UserCtrl'});
|
||||
}
|
||||
break;
|
||||
case 'ULTIMATE_GEAR_ACHIEVEMENT':
|
||||
$rootScope.openModal('achievements/ultimateGear', {controller:'UserCtrl'});
|
||||
break;
|
||||
case 'REBIRTH_ACHIEVEMENT':
|
||||
$rootScope.openModal('achievements/rebirth', {controller:'UserCtrl', size: 'sm'});
|
||||
break;
|
||||
case 'NEW_CONTRIBUTOR_LEVEL':
|
||||
$rootScope.openModal('achievements/contributor',{controller:'UserCtrl'});
|
||||
break;
|
||||
case 'CRON':
|
||||
if (notification.data) {
|
||||
if (notification.data.hp) Notification.hp(notification.data.hp, 'hp');
|
||||
if (notification.data.mp) Notification.mp(notification.data.mp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
markAsRead = false; // If the notification is not implemented, skip it
|
||||
break;
|
||||
}
|
||||
|
||||
if (markAsRead) User.readNotification(notification.id);
|
||||
});
|
||||
|
||||
User.user.notifications = []; // reset the notifications
|
||||
}
|
||||
|
||||
// Since we don't use localStorage anymore, notifications for achievements and new contributor levels
|
||||
// are now stored user.notifications.
|
||||
$rootScope.$watchCollection('userNotifications', function (after) {
|
||||
if (!User.user._wrapped) return;
|
||||
handleUserNotifications(after);
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.achievements.ultimateGearSets', function(after, before){
|
||||
if (_.isEqual(after,before) || !_.contains(User.user.achievements.ultimateGearSets, true)) return;
|
||||
$rootScope.openModal('achievements/ultimateGear', {controller:'UserCtrl'});
|
||||
var handleUserNotificationsOnFirstSync = _.once(function () {
|
||||
handleUserNotifications($rootScope.userNotifications);
|
||||
});
|
||||
$rootScope.$on('userUpdated', handleUserNotificationsOnFirstSync);
|
||||
|
||||
// TODO what about this?
|
||||
$rootScope.$watch('user.achievements', function(){
|
||||
$rootScope.playSound('Achievement_Unlocked');
|
||||
}, true);
|
||||
|
||||
$rootScope.$watch('user.flags.armoireEmpty', function(after,before){
|
||||
if (before == undefined || after == before || after == false) return;
|
||||
if (after == before || after == false) return;
|
||||
$rootScope.openModal('armoireEmpty');
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.achievements.rebirths', function(after, before){
|
||||
if(after === before) return;
|
||||
$rootScope.openModal('achievements/rebirth', {controller:'UserCtrl', size: 'sm'});
|
||||
});
|
||||
|
||||
$rootScope.$watch('user.contributor.level', function(after, before){
|
||||
if (after === before || after < before || after == null) return;
|
||||
$rootScope.openModal('achievements/contributor',{controller:'UserCtrl'});
|
||||
});
|
||||
|
||||
// Completed quest modal
|
||||
$scope.$watch('user.party.quest.completed', function(after, before){
|
||||
if (!after) return;
|
||||
|
||||
Reference in New Issue
Block a user