diff --git a/static/js/pages/user-view.js b/static/js/pages/user-view.js index 338b2e25c..ec78f24b7 100644 --- a/static/js/pages/user-view.js +++ b/static/js/pages/user-view.js @@ -10,7 +10,7 @@ }) }]); - function UserViewCtrl($scope, $routeParams, $timeout, ApiService, UserService, UIService, AvatarService, Config, ExternalLoginService) { + function UserViewCtrl($scope, $routeParams, $timeout, ApiService, UserService, UIService, AvatarService, Config, ExternalLoginService, CookieService) { var username = $routeParams.username; $scope.Config = Config; @@ -186,14 +186,14 @@ }; - $scope.notificationsPermissionsEnabled = Notification + $scope.notificationsPermissionsEnabled = window['Notification'] && Notification.permission === 'granted' - && localStorage.getItem('quay.enabledDesktopNotifications') === 'on'; + && CookieService.get('quay.enabledDesktopNotifications') === 'on'; - $scope.desktopNotificationsPermissionIsDisabled = () => Notification.permission === 'denied'; + $scope.desktopNotificationsPermissionIsDisabled = () => window['Notification'] && Notification.permission === 'denied'; $scope.toggleDesktopNotifications = () => { - if (!Notification) { // unsupported in IE & some older browsers, we'll just tell the user it's not available + if (!window['Notification']) { // unsupported in IE & some older browsers, we'll just tell the user it's not available bootbox.dialog({ "message": 'Desktop Notifications unsupported in this browser', "title": 'Unsupported Option', @@ -208,24 +208,24 @@ return; } - if (localStorage.getItem('quay.enabledDesktopNotifications') === 'on') { - localStorage.setItem('quay.enabledDesktopNotifications', 'off'); - localStorage.removeItem('quay.notifications.mostRecentTimestamp'); + if (CookieService.get('quay.enabledDesktopNotifications') === 'on') { + CookieService.putPermanent('quay.enabledDesktopNotifications', 'off'); + CookieService.clear('quay.notifications.mostRecentTimestamp'); $scope.notificationsPermissionsEnabled = false; } else { if (Notification.permission === 'default') { Notification.requestPermission() .then((newPermission) => { if (newPermission === 'granted') { - localStorage.setItem('quay.enabledDesktopNotifications', 'on'); + CookieService.putPermanent('quay.enabledDesktopNotifications', 'on'); $scope.notificationsPermissionsEnabled = true; } else { $scope.notificationsPermissionsEnabled = false; } }); } else if (Notification.permission === 'granted') { - localStorage.setItem('quay.enabledDesktopNotifications', 'on'); - localStorage.setItem('quay.notifications.mostRecentTimestamp', new Date().getTime().toString()); + CookieService.putPermanent('quay.enabledDesktopNotifications', 'on'); + CookieService.putPermanent('quay.notifications.mostRecentTimestamp', new Date().getTime().toString()); $scope.notificationsPermissionsEnabled = true; } } diff --git a/static/js/services/notification-service.js b/static/js/services/notification-service.js index 323a11e3c..94c0b8bad 100644 --- a/static/js/services/notification-service.js +++ b/static/js/services/notification-service.js @@ -3,9 +3,9 @@ * in the sidebar) and provides helper methods for working with them. */ angular.module('quay').factory('NotificationService', - ['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'UserService', 'Features', 'Config', '$location', 'VulnerabilityService', + ['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'CookieService', 'Features', 'Config', '$location', 'VulnerabilityService', -function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, UserService, Features, Config, $location, VulnerabilityService) { +function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, CookieService, Features, Config, $location, VulnerabilityService) { var notificationService = { 'user': null, 'notifications': [], @@ -267,8 +267,7 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P notificationService.additionalNotifications = resp['additional']; notificationService.notificationClasses = notificationService.getClasses(notificationService.notifications); - if (notificationService.notifications.length > 0 && localStorage.getItem('quay.enabledDesktopNotifications') === 'on') { - console.log(notificationService); + if (notificationService.notifications.length > 0 && CookieService.get('quay.enabledDesktopNotifications') === 'on') { notificationService.sendBrowserNotifications(); } }); @@ -284,7 +283,7 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P }; notificationService.sendBrowserNotifications = () => { - let mostRecentTimestamp = parseInt(localStorage.getItem('quay.notifications.mostRecentTimestamp'), 10); + let mostRecentTimestamp = parseInt(CookieService.get('quay.notifications.mostRecentTimestamp'), 10); if (!mostRecentTimestamp) { mostRecentTimestamp = new Date(notificationService.notifications[0].created).getTime(); } @@ -300,12 +299,12 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P } new Notification(message, { - icon: 'http://quay.io/static/img/quay-logo.png', - image: 'http://quay.io/static/img/quay-logo.png', + icon: window.location.origin + '/static/img/quay-logo.png', + image: window.location.origin + '/static/img/quay-logo.png', }); const newTimestamp = new Date(newNotifications[0].created).getTime(); - localStorage.setItem('quay.notifications.mostRecentTimestamp', newTimestamp.toString()); + CookieService.putPermanent('quay.notifications.mostRecentTimestamp', newTimestamp.toString()); } }; diff --git a/static/partials/user-view.html b/static/partials/user-view.html index 4441934e8..9e3a90dc3 100644 --- a/static/partials/user-view.html +++ b/static/partials/user-view.html @@ -183,7 +183,7 @@ Note: Desktop notifications have been disabled in your browser. + >Note: Desktop notifications have been disabled, or are unavailable, in your browser.