Skip to content

Commit

Permalink
refactor(NotificationService): getNewNotifications() (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Oct 3, 2023
1 parent c0f3fb1 commit 9435534
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
30 changes: 13 additions & 17 deletions src/assets/wise5/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20951,21 +20951,21 @@ If this problem continues, let your teacher know and move on to the next activit
<source>You have new replies to your discussion post!</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/notificationService.ts</context>
<context context-type="linenumber">131</context>
<context context-type="linenumber">132</context>
</context-group>
</trans-unit>
<trans-unit id="199088045976822823" datatype="html">
<source>You have new feedback from your teacher!</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/notificationService.ts</context>
<context context-type="linenumber">133</context>
<context context-type="linenumber">134</context>
</context-group>
</trans-unit>
<trans-unit id="5013145827213980080" datatype="html">
<source>You have new feedback!</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/notificationService.ts</context>
<context context-type="linenumber">148</context>
<context context-type="linenumber">149</context>
</context-group>
</trans-unit>
<trans-unit id="4484876679373170309" datatype="html">
Expand Down

0 comments on commit 9435534

Please sign in to comment.