Moved notifications to be read after yesterdailies (#8872)

* Moved notifications to be read after yesterdailies

* Prevent when user needs cron

* Updated tests
This commit is contained in:
Keith Holliday 2017-07-16 10:24:09 -06:00 committed by Sabe Jones
parent 78ba596504
commit f8571ec5d5
2 changed files with 8 additions and 4 deletions

View file

@ -6,6 +6,7 @@ describe('Notification Controller', function() {
beforeEach(function() { beforeEach(function() {
user = specHelper.newUser(); user = specHelper.newUser();
user._id = "unique-user-id"; user._id = "unique-user-id";
user.needsCron = false;
var userSync = sinon.stub().returns({ var userSync = sinon.stub().returns({
then: function then (f) { f(); } then: function then (f) { f(); }

View file

@ -39,6 +39,7 @@ habitrpg.controller('NotificationCtrl',
if (yesterDailies.length === 0) { if (yesterDailies.length === 0) {
User.runCron().then(function () { User.runCron().then(function () {
isRunningYesterdailies = false; isRunningYesterdailies = false;
handleUserNotifications(User.user);
}); });
return; return;
}; };
@ -73,6 +74,7 @@ habitrpg.controller('NotificationCtrl',
User.runCron() User.runCron()
.then(function () { .then(function () {
isRunningYesterdailies = false; isRunningYesterdailies = false;
handleUserNotifications(User.user);
}); });
}; };
}], }],
@ -313,13 +315,14 @@ habitrpg.controller('NotificationCtrl',
// are now stored in user.notifications. // are now stored in user.notifications.
$rootScope.$watchCollection('userNotifications', function (after) { $rootScope.$watchCollection('userNotifications', function (after) {
if (!User.user._wrapped) return; if (!User.user._wrapped) return;
if (User.user.needsCron) return;
handleUserNotifications(after); handleUserNotifications(after);
}); });
var handleUserNotificationsOnFirstSync = _.once(function () { // var handleUserNotificationsOnFirstSync = _.once(function () {
handleUserNotifications($rootScope.userNotifications); // handleUserNotifications($rootScope.userNotifications);
}); // });
$rootScope.$on('userUpdated', handleUserNotificationsOnFirstSync); // $rootScope.$on('userUpdated', handleUserNotificationsOnFirstSync);
// TODO what about this? // TODO what about this?
$rootScope.$watch('user.achievements', function(){ $rootScope.$watch('user.achievements', function(){