better update when notification panel is open #55

This commit is contained in:
Nicolas Constant 2019-03-28 00:57:09 -04:00
parent e61a7cd49a
commit 1fa3483a5e
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 17 additions and 7 deletions

View File

@ -61,6 +61,7 @@ export class MentionsComponent implements OnInit, OnDestroy {
this.userNotificationService.markMentionsAsRead(this.account.info); this.userNotificationService.markMentionsAsRead(this.account.info);
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => { 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); const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
if(userNotification && userNotification.mentions){ if(userNotification && userNotification.mentions){
userNotification.mentions.forEach((mention: Status) => { userNotification.mentions.forEach((mention: Status) => {
@ -69,6 +70,7 @@ export class MentionsComponent implements OnInit, OnDestroy {
}); });
} }
this.lastId = userNotification.lastId; 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) this.mastodonService.getNotifications(this.account.info, ['follow', 'favourite', 'reblog'], this.lastId)
.then((result: Notification[]) => { .then((result: Notification[]) => {
const statuses = result.map(x => x.status); const statuses = result.map(x => x.status);
if (statuses.length === 0) { if (statuses.length === 0) {
this.maxReached = true; this.maxReached = true;

View File

@ -64,6 +64,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
this.userNotificationService.markNotificationAsRead(this.account.info); this.userNotificationService.markNotificationAsRead(this.account.info);
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => { 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); const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
if(userNotification && userNotification.notifications){ if(userNotification && userNotification.notifications){
userNotification.notifications.forEach((notification: Notification) => { userNotification.notifications.forEach((notification: Notification) => {
@ -72,6 +73,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
}); });
} }
this.lastId = userNotification.lastId; this.lastId = userNotification.lastId;
this.userNotificationService.markNotificationAsRead(this.account.info);
}); });
} }

View File

@ -85,10 +85,10 @@ export class UserNotificationService {
} }
private analyseNotifications(userNotification: UserNotification): UserNotification { private analyseNotifications(userNotification: UserNotification): UserNotification {
if(userNotification.allNotifications.length > 30){ if (userNotification.allNotifications.length > 30) {
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 newNotifications = userNotification.allNotifications.filter(x => x.type !== 'mention');
const newMentions = userNotification.allNotifications.filter(x => x.type === 'mention').map(x => x.status); const newMentions = userNotification.allNotifications.filter(x => x.type === 'mention').map(x => x.status);
@ -130,15 +130,21 @@ export class UserNotificationService {
markMentionsAsRead(account: AccountInfo) { markMentionsAsRead(account: AccountInfo) {
let currentNotifications = this.userNotifications.value; let currentNotifications = this.userNotifications.value;
const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id); 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) { markNotificationAsRead(account: AccountInfo) {
let currentNotifications = this.userNotifications.value; let currentNotifications = this.userNotifications.value;
const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id); 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);
}
} }
} }