Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(NotificationService): getNewNotifications() #1439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20937,21 +20937,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