From 73fed5f5085a937b32a94fa04b8d6aa3179a1e1f Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Fri, 7 Jul 2017 23:41:10 +0200 Subject: [PATCH] [fix] Notifications: do not mark as read if not auth --- www/js/services/wallet-services.js | 3 +++ .../es/js/controllers/app-controllers.js | 8 ++++++++ .../controllers/notification-controllers.js | 15 ++++++++++++-- .../es/js/services/notification-services.js | 20 +++++++++++++------ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index ff0c1234d..99e2f4fc3 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -157,6 +157,9 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se return loadData(loadOptions); } }).then(function() { + if (options && options.silent) { + UIUtils.loading.hide(); + } return keepAuth ? data : angular.merge({}, data, authData); }); }, diff --git a/www/plugins/es/js/controllers/app-controllers.js b/www/plugins/es/js/controllers/app-controllers.js index 4d51aeb38..2a42c35f9 100644 --- a/www/plugins/es/js/controllers/app-controllers.js +++ b/www/plugins/es/js/controllers/app-controllers.js @@ -89,6 +89,14 @@ function ESMenuExtendController($scope, $state, PluginService, esSettings, UIUti }; $scope.showMessagesPopover = function(event) { + // Make sure tobe auth before opening this popover + if (!csWallet.isAuth()) { + return csWallet.auth().then(function(){ + UIUtils.loading.hide(); + return $scope.showMessagesPopover(event); // loop + }); + } + return UIUtils.popover.show(event, { templateUrl :'plugins/es/templates/message/popover_message.html', scope: $scope, diff --git a/www/plugins/es/js/controllers/notification-controllers.js b/www/plugins/es/js/controllers/notification-controllers.js index 88f7f39f8..d84635dab 100644 --- a/www/plugins/es/js/controllers/notification-controllers.js +++ b/www/plugins/es/js/controllers/notification-controllers.js @@ -16,7 +16,7 @@ angular.module('cesium.es.notification.controllers', ['cesium.es.services']) } }, data: { - auth: true + login: true } }) ; @@ -95,6 +95,14 @@ function NotificationsController($scope, $rootScope, $ionicPopover, $state, $tim }; $scope.markAllAsRead = function() { + // Make sure to be auth before doing this + if (!csWallet.isAuth()) { + return csWallet.auth().then(function(){ + UIUtils.loading.hide(); + return $scope.markAllAsRead(); // loop + }); + } + $scope.hideActionsPopover(); if (!$scope.search.results.length) return; @@ -125,7 +133,10 @@ function NotificationsController($scope, $rootScope, $ionicPopover, $state, $tim }; $scope.select = function(item) { - if (item.markAsRead && typeof item.markAsRead == 'function') item.markAsRead(); + + if (item.markAsRead && typeof item.markAsRead == 'function') { + $timeout(item.markAsRead); + } if (item.state) { $state.go(item.state, item.stateParams); } diff --git a/www/plugins/es/js/services/notification-services.js b/www/plugins/es/js/services/notification-services.js index f84b539b6..ff68c0423 100644 --- a/www/plugins/es/js/services/notification-services.js +++ b/www/plugins/es/js/services/notification-services.js @@ -175,13 +175,21 @@ angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es console.error('[ES] [notification] Could not mark as read: no \'id\' found!', notification); return; } + + // user not auth: could not mark as read + if (!csWallet.isAuth()) return; + notification.read = true; - CryptoUtils.sign(notification.hash, csWallet.data.keypair) - .then(function(signature){ - return that.raw.postReadById(signature, {id:notification.id}); - }) - .catch(function(err) { - console.error('[ES] [notification] Error while trying to mark event as read.', err); + return csWallet.getKeypair() + .then(function(keypair) { + return CryptoUtils.sign(notification.hash, keypair) + .then(function(signature){ + return that.raw.postReadById(signature, {id:notification.id}); + }) + .catch(function(err) { + console.error('[ES] [notification] Error while trying to mark event as read.', err); + }); + }); } -- GitLab