Use cookie service and small cleanup for pr

This commit is contained in:
Sam Chow 2018-05-04 17:11:47 -04:00
parent 2d3583fb44
commit 6fe579119b
3 changed files with 19 additions and 20 deletions

View file

@ -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;
}
}