in ui/src/app/notifications/notifications.component.ts [88:159]
ngOnInit() {
this.breadcrumbService.updateBreadcrumb([{ label: 'Notifications' }]);
this.getPipelinesWithNotifications();
this.subscription = timer(0, 5000)
.pipe(
filter(
() =>
this.currentlySelectedNotification !== undefined &&
this.allNotifications.size > 0,
),
switchMap(() =>
this.notificationService.getNotificationsFromTime(
this.lastFetchTime,
),
),
)
.subscribe(notifications => {
let scrollToBottom = false;
if (notifications.length > 0) {
if (
this.notificationContainer.nativeElement.scrollHeight -
this.notificationContainer.nativeElement
.scrollTop <=
this.notificationContainer.nativeElement
.clientHeight +
10 &&
this.notificationContainer.nativeElement.scrollHeight -
this.notificationContainer.nativeElement
.scrollTop >=
this.notificationContainer.nativeElement
.clientHeight -
10
) {
scrollToBottom = true;
}
this.newEventArriving = true;
notifications.forEach(notification => {
const notificationId =
NotificationUtils.makeNotificationId(
notification.correspondingPipelineId,
notification.title,
);
const existingNots =
this.allNotifications.get(notificationId);
existingNots.push(notification);
this.allNotifications.set(notificationId, existingNots);
if (
this.currentlySelectedNotificationId ===
notificationId
) {
this.liveOffset++;
notification.read = true;
setTimeout(() => {
this.notificationService
.updateNotification(notification)
.subscribe();
}, 500);
} else {
this.newNotificationInfo[notificationId] = true;
}
});
if (scrollToBottom) {
setTimeout(() => {
this.scrollToBottom();
});
}
}
this.lastFetchTime = new Date().getTime();
this.newEventArriving = false;
});
}