better handling of notifications and mentions
This commit is contained in:
parent
3d017da166
commit
656e2dca00
|
@ -67,17 +67,24 @@ 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
|
||||
this.processNewMentions(userNotifications);
|
||||
if(this.statuses.length < 20) this.scrolledToBottom();
|
||||
});
|
||||
}
|
||||
|
||||
private processNewMentions(userNotifications: UserNotification[]) {
|
||||
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
|
||||
if (userNotification && userNotification.mentions) {
|
||||
userNotification.mentions.forEach((mention: Status) => {
|
||||
const statusWrapper = new StatusWrapper(mention, this.account.info);
|
||||
this.statuses.push(statusWrapper);
|
||||
});
|
||||
let orderedMentions = [...userNotification.mentions].reverse();
|
||||
for (let m of orderedMentions) {
|
||||
if (!this.statuses.find(x => x.status.id === m.id)) {
|
||||
const statusWrapper = new StatusWrapper(m, this.account.info);
|
||||
this.statuses.unshift(statusWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastId = userNotification.lastId;
|
||||
this.userNotificationService.markMentionsAsRead(this.account.info);
|
||||
});
|
||||
}
|
||||
|
||||
onScroll() {
|
||||
|
|
|
@ -68,17 +68,24 @@ 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
|
||||
this.processNewNotifications(userNotifications);
|
||||
if(this.notifications.length < 20) this.scrolledToBottom();
|
||||
});
|
||||
}
|
||||
|
||||
private processNewNotifications(userNotifications: UserNotification[]) {
|
||||
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
|
||||
if (userNotification && userNotification.notifications) {
|
||||
userNotification.notifications.forEach((notification: Notification) => {
|
||||
const notificationWrapper = new NotificationWrapper(notification, this.account.info);
|
||||
this.notifications.push(notificationWrapper);
|
||||
});
|
||||
let orderedNotifications = [...userNotification.notifications].reverse();
|
||||
for (let n of orderedNotifications) {
|
||||
const notificationWrapper = new NotificationWrapper(n, this.account.info);
|
||||
if (!this.notifications.find(x => x.wrapperId === notificationWrapper.wrapperId)) {
|
||||
this.notifications.unshift(notificationWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastId = userNotification.lastId;
|
||||
this.userNotificationService.markNotificationAsRead(this.account.info);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,8 +158,10 @@ class NotificationWrapper {
|
|||
break;
|
||||
}
|
||||
this.account = notification.account;
|
||||
this.wrapperId = `${this.type}-${notification.id}`;
|
||||
}
|
||||
|
||||
wrapperId: string;
|
||||
account: Account;
|
||||
status: StatusWrapper;
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow';
|
||||
|
|
Loading…
Reference in New Issue