From 9435534b8d4bdb5f450dbbd6808388ef9390cfdb Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Tue, 3 Oct 2023 15:58:06 -0700 Subject: [PATCH] refactor(NotificationService): getNewNotifications() (#1439) --- .../wise5/services/notificationService.ts | 30 ++++++++----------- src/messages.xlf | 6 ++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/assets/wise5/services/notificationService.ts b/src/assets/wise5/services/notificationService.ts index 13f7677b4b9..dbb3e036753 100644 --- a/src/assets/wise5/services/notificationService.ts +++ b/src/assets/wise5/services/notificationService.ts @@ -106,11 +106,12 @@ export class NotificationService { } getNewNotifications(): any[] { - let newNotificationAggregates = []; - for (const notification of this.notifications) { - if (notification.timeDismissed == null) { - let notificationNodeId = notification.nodeId; - let notificationType = notification.type; + const newNotificationAggregates = []; + this.notifications + .filter((notification) => notification.timeDismissed == null) + .forEach((notification) => { + const notificationNodeId = notification.nodeId; + const notificationType = notification.type; let newNotificationForNodeIdAndTypeExists = false; for (const newNotificationAggregate of newNotificationAggregates) { if ( @@ -138,7 +139,7 @@ export class NotificationService { const annotationId = (notification.data as any).annotationId; if (annotationId != null) { - let annotation = this.annotationService.getAnnotationById(annotationId); + const annotation = this.annotationService.getAnnotationById(annotationId); if (annotation != null && annotation.notebookItemId != null) { notebookItemId = annotation.notebookItemId; } @@ -149,24 +150,19 @@ export class NotificationService { } else { message = notification.message; } - const newNotificationAggregate = { + newNotificationAggregates.push({ latestNotificationTimestamp: notification.timeGenerated, message: message, nodeId: notificationNodeId, notebookItemId: notebookItemId, notifications: [notification], type: notificationType - }; - newNotificationAggregates.push(newNotificationAggregate); + }); } - } - } - - // sort the aggregates by latestNotificationTimestamp, latest -> oldest - newNotificationAggregates.sort((n1, n2) => { - return n2.latestNotificationTimestamp - n1.latestNotificationTimestamp; - }); - return newNotificationAggregates; + }); + return newNotificationAggregates.sort( + (n1, n2) => n2.latestNotificationTimestamp - n1.latestNotificationTimestamp + ); } setNotificationNodePositionAndTitle(notification: Notification) { diff --git a/src/messages.xlf b/src/messages.xlf index c5525d9c17e..00a6cc245fc 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -20951,21 +20951,21 @@ If this problem continues, let your teacher know and move on to the next activit You have new replies to your discussion post! src/assets/wise5/services/notificationService.ts - 131 + 132 You have new feedback from your teacher! src/assets/wise5/services/notificationService.ts - 133 + 134 You have new feedback! src/assets/wise5/services/notificationService.ts - 148 + 149