From 8ebccda1aba35dd80e8c02e2cfd0ec7220db266d Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Mon, 9 Mar 2020 15:34:19 +0100 Subject: [PATCH] [fix] Notifications: new notification (received by WebScoket) are not added to popover ("duplicated id" error, from the ng-repeater) --- www/plugins/es/js/entities/notification.js | 5 +++-- www/plugins/es/js/services/notification-services.js | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/www/plugins/es/js/entities/notification.js b/www/plugins/es/js/entities/notification.js index eee62d73..942764b5 100644 --- a/www/plugins/es/js/entities/notification.js +++ b/www/plugins/es/js/entities/notification.js @@ -11,14 +11,15 @@ function EsNotification(json, markAsReadCallback) { // Avoid undefined errors json = json || {}; + that.id = json.id || ('' + Date.now()); // Keep id if exists, otherwise create it from timestamp that.type = json.type && json.type.toLowerCase(); that.time = json.time; that.hash = json.hash; that.read = json.read_signature ? true : false; - that.message = json.reference && messagePrefixes[json.reference.index] ? + that.message = json.code && (json.reference && messagePrefixes[json.reference.index] ? messagePrefixes[json.reference.index] + json.code : - 'EVENT.' + json.code; + 'EVENT.' + json.code) ||Â json.message; that.params = json.params; if (markAsReadCallback && (typeof markAsReadCallback === "function") ) { diff --git a/www/plugins/es/js/services/notification-services.js b/www/plugins/es/js/services/notification-services.js index 630c0dcf..3591a6fb 100644 --- a/www/plugins/es/js/services/notification-services.js +++ b/www/plugins/es/js/services/notification-services.js @@ -118,7 +118,7 @@ angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es // Add some wallet events as notifications var time = csHttp.date.now() - filterTranslations.MEDIAN_TIME_OFFSET; var result = (wallet.data.events || []).reduce(function(res, event) { - if (event.type != "warn" && event.type != "error") return res; // Keep only warn and error events + if (event.type !== "warn" && event.type !== "error") return res; // Keep only warn and error events var notification = new EsNotification({}, function(self) { if (!self.read) { self.read = true; @@ -127,12 +127,12 @@ angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es } } }); - notification.id=event.code; + notification.id= event.code; + notification.time= time; notification.read = false; notification.state = 'app.view_wallet'; notification.avatarIcon = 'ion-alert-circled'; notification.icon = 'ion-alert-circled assertive'; - notification.time = time; notification.message = event.message; notification.messageParams = event.messageParams; return res.concat(notification); @@ -200,6 +200,7 @@ angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es } var notification = new EsNotification(event, markNotificationAsRead); + notification.id = event.id ||Â notification.id; // Extend the notification entity return csWot.extendAll([notification]) -- GitLab