From 1fa3483a5ee4a062623af2b895382946e82ff55c Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 28 Mar 2019 00:57:09 -0400 Subject: [PATCH] better update when notification panel is open #55 --- .../mentions/mentions.component.ts | 4 +++- .../notifications/notifications.component.ts | 2 ++ src/app/services/user-notification.service.ts | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app/components/floating-column/manage-account/mentions/mentions.component.ts b/src/app/components/floating-column/manage-account/mentions/mentions.component.ts index 2db3cde7..3c2cd5cb 100644 --- a/src/app/components/floating-column/manage-account/mentions/mentions.component.ts +++ b/src/app/components/floating-column/manage-account/mentions/mentions.component.ts @@ -61,6 +61,7 @@ export class MentionsComponent implements OnInit, OnDestroy { this.userNotificationService.markMentionsAsRead(this.account.info); this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => { + this.statuses.length = 0; //TODO: don't reset, only add the new ones const userNotification = userNotifications.find(x => x.account.id === this.account.info.id); if(userNotification && userNotification.mentions){ userNotification.mentions.forEach((mention: Status) => { @@ -69,6 +70,7 @@ export class MentionsComponent implements OnInit, OnDestroy { }); } this.lastId = userNotification.lastId; + this.userNotificationService.markMentionsAsRead(this.account.info); }); } @@ -88,7 +90,7 @@ export class MentionsComponent implements OnInit, OnDestroy { this.mastodonService.getNotifications(this.account.info, ['follow', 'favourite', 'reblog'], this.lastId) .then((result: Notification[]) => { - + const statuses = result.map(x => x.status); if (statuses.length === 0) { this.maxReached = true; diff --git a/src/app/components/floating-column/manage-account/notifications/notifications.component.ts b/src/app/components/floating-column/manage-account/notifications/notifications.component.ts index 6fc26c3c..9e88de03 100644 --- a/src/app/components/floating-column/manage-account/notifications/notifications.component.ts +++ b/src/app/components/floating-column/manage-account/notifications/notifications.component.ts @@ -64,6 +64,7 @@ export class NotificationsComponent implements OnInit, OnDestroy { this.userNotificationService.markNotificationAsRead(this.account.info); this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => { + this.notifications.length = 0; //TODO: don't reset, only add the new ones const userNotification = userNotifications.find(x => x.account.id === this.account.info.id); if(userNotification && userNotification.notifications){ userNotification.notifications.forEach((notification: Notification) => { @@ -72,6 +73,7 @@ export class NotificationsComponent implements OnInit, OnDestroy { }); } this.lastId = userNotification.lastId; + this.userNotificationService.markNotificationAsRead(this.account.info); }); } diff --git a/src/app/services/user-notification.service.ts b/src/app/services/user-notification.service.ts index 2d431722..34002a07 100644 --- a/src/app/services/user-notification.service.ts +++ b/src/app/services/user-notification.service.ts @@ -85,10 +85,10 @@ export class UserNotificationService { } private analyseNotifications(userNotification: UserNotification): UserNotification { - if(userNotification.allNotifications.length > 30){ + if (userNotification.allNotifications.length > 30) { userNotification.allNotifications.length = 30; } - userNotification.lastId = userNotification.allNotifications[userNotification.allNotifications.length - 1].id; + userNotification.lastId = userNotification.allNotifications[userNotification.allNotifications.length - 1].id; const newNotifications = userNotification.allNotifications.filter(x => x.type !== 'mention'); const newMentions = userNotification.allNotifications.filter(x => x.type === 'mention').map(x => x.status); @@ -130,15 +130,21 @@ export class UserNotificationService { markMentionsAsRead(account: AccountInfo) { let currentNotifications = this.userNotifications.value; const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id); - currentAccountNotifications.hasNewMentions = false; - this.userNotifications.next(currentNotifications); + + if (currentAccountNotifications.hasNewMentions === true) { + currentAccountNotifications.hasNewMentions = false; + this.userNotifications.next(currentNotifications); + } } markNotificationAsRead(account: AccountInfo) { let currentNotifications = this.userNotifications.value; const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id); - currentAccountNotifications.hasNewNotifications = false; - this.userNotifications.next(currentNotifications); + + if (currentAccountNotifications.hasNewNotifications === true) { + currentAccountNotifications.hasNewNotifications = false; + this.userNotifications.next(currentNotifications); + } } }