added new properties to detect new notifications
This commit is contained in:
parent
068c3d4163
commit
66df78074b
|
@ -73,16 +73,12 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
|||
});
|
||||
|
||||
this.notificationSub = this.userNotificationServiceService.userNotifications.subscribe((notifications: UserNotification[]) => {
|
||||
|
||||
notifications.forEach((notification: UserNotification) => {
|
||||
const acc = this.accounts.find(x => x.info.id === notification.account.id);
|
||||
if(acc){
|
||||
acc.hasActivityNotifications = notification.hasNewMentions || notification.hasNewNotifications;
|
||||
}
|
||||
});
|
||||
|
||||
console.warn('new notifications');
|
||||
console.warn(notifications);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ export interface Mention {
|
|||
export interface Notification {
|
||||
id: string;
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow';
|
||||
created_at: string;
|
||||
created_at: Date;
|
||||
account: Account;
|
||||
status?: Status;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ export class NotificationService {
|
|||
}
|
||||
|
||||
public notifyHttpError(err: HttpErrorResponse){
|
||||
console.error(err);
|
||||
console.error(err.message);
|
||||
// let message = `${err.status}: ${err.statusText}`;
|
||||
let message = `${err.statusText}`;
|
||||
|
|
|
@ -98,57 +98,41 @@ export class UserNotificationService {
|
|||
const currentNotifications = userNotification.notifications;
|
||||
const currentMentions = userNotification.mentions;
|
||||
|
||||
const lastMention = userNotification.mentions[0];
|
||||
let lastMentionNotification: Notification;
|
||||
if (lastMention) {
|
||||
lastMentionNotification = userNotification.allNotifications.find(x => x.type === 'mention' && x.status.id === lastMention.id);
|
||||
}
|
||||
const lastNotification = userNotification.notifications[0];
|
||||
|
||||
userNotification.notifications = [...newNotifications, ...currentNotifications];
|
||||
userNotification.mentions = [...newMentions, ...currentMentions];
|
||||
|
||||
const accountSettings = this.toolsService.getAccountSettings(account);
|
||||
|
||||
if(accountSettings.lastMentionReadId && userNotification.mentions[0] && accountSettings.lastMentionReadId !== userNotification.mentions[0].id){
|
||||
if (accountSettings.lastMentionReadId && lastMention && accountSettings.lastMentionReadId !== lastMention.id && lastMentionNotification.created_at > accountSettings.lastMentionCreationDate) {
|
||||
userNotification.hasNewMentions = true;
|
||||
} else {
|
||||
userNotification.hasNewMentions = false;
|
||||
}
|
||||
|
||||
if(accountSettings.lastNotificationReadId && userNotification.notifications[0] && accountSettings.lastNotificationReadId !== userNotification.notifications[0].id){
|
||||
if (accountSettings.lastNotificationReadId && lastNotification && accountSettings.lastNotificationReadId !== lastNotification.id && lastNotification.created_at > accountSettings.lastNotificationCreationDate) {
|
||||
userNotification.hasNewNotifications = true;
|
||||
} else {
|
||||
userNotification.hasNewNotifications = false;
|
||||
}
|
||||
|
||||
if((!accountSettings.lastMentionReadId && userNotification.mentions[0])
|
||||
|| (!accountSettings.lastNotificationReadId && userNotification.notifications[0])){
|
||||
accountSettings.lastMentionReadId = userNotification.mentions[0].id;
|
||||
accountSettings.lastNotificationReadId = userNotification.notifications[0].id;
|
||||
if ((!accountSettings.lastMentionReadId && !accountSettings.lastNotificationCreationDate) && lastMention && lastMentionNotification) {
|
||||
accountSettings.lastMentionReadId = lastMention.id;
|
||||
accountSettings.lastMentionCreationDate = lastMentionNotification.created_at;
|
||||
this.toolsService.saveAccountSettings(accountSettings);
|
||||
}
|
||||
|
||||
// if (!currentNotifications) {
|
||||
// userNotification.notifications = newNotifications;
|
||||
|
||||
// } else if (currentNotifications.length === 0) {
|
||||
// if (newNotifications.length > 0) {
|
||||
// userNotification.hasNewNotifications = true;
|
||||
// }
|
||||
// userNotification.notifications = newNotifications;
|
||||
|
||||
// } else if (newNotifications.length > 0) {
|
||||
// userNotification.hasNewNotifications = currentNotifications[0].id !== newNotifications[0].id;
|
||||
// userNotification.notifications = [...newNotifications, ...currentNotifications];
|
||||
// }
|
||||
|
||||
// if (!currentNotifications) {
|
||||
// userNotification.mentions = newMentions;
|
||||
|
||||
// } else if (currentMentions.length === 0) {
|
||||
// if (newMentions.length > 0) {
|
||||
// userNotification.hasNewMentions = true;
|
||||
// }
|
||||
// userNotification.mentions = newMentions;
|
||||
|
||||
// } else if (newMentions.length > 0) {
|
||||
// userNotification.hasNewMentions = currentMentions[0].id !== newMentions[0].id;
|
||||
// userNotification.mentions = [...newMentions, ...currentMentions];
|
||||
// }
|
||||
if((!accountSettings.lastNotificationReadId || !accountSettings.lastNotificationCreationDate) && lastNotification){
|
||||
accountSettings.lastNotificationReadId = lastNotification.id;
|
||||
accountSettings.lastNotificationCreationDate = lastNotification.created_at;
|
||||
this.toolsService.saveAccountSettings(accountSettings);
|
||||
}
|
||||
|
||||
return userNotification;
|
||||
}
|
||||
|
@ -158,7 +142,7 @@ export class UserNotificationService {
|
|||
const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id);
|
||||
|
||||
const lastMention = currentAccountNotifications.mentions[0];
|
||||
if(lastMention){
|
||||
if (lastMention) {
|
||||
// const lastNotification = currentAccountNotifications.allNotifications.find(x => x.status && x.status.id === lastMention.id);
|
||||
const settings = this.toolsService.getAccountSettings(account);
|
||||
settings.lastMentionReadId = lastMention.id;
|
||||
|
@ -176,7 +160,7 @@ export class UserNotificationService {
|
|||
const currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id);
|
||||
|
||||
const lastNotification = currentAccountNotifications.notifications[0];
|
||||
if(lastNotification){
|
||||
if (lastNotification) {
|
||||
const settings = this.toolsService.getAccountSettings(account);
|
||||
settings.lastNotificationReadId = lastNotification.id;
|
||||
this.toolsService.saveAccountSettings(settings);
|
||||
|
|
|
@ -20,7 +20,9 @@ export class AccountSettings {
|
|||
displayMention: boolean = true;
|
||||
displayNotifications: boolean = true;
|
||||
lastMentionReadId: string;
|
||||
lastMentionCreationDate: Date;
|
||||
lastNotificationReadId: string;
|
||||
lastNotificationCreationDate: Date;
|
||||
}
|
||||
|
||||
export class GlobalSettings {
|
||||
|
|
Loading…
Reference in New Issue