( previousAccountNotifications: AccountNotifications[], newAccountNotifications: AccountNotifications[], )
| 6 | * Find notifications that exist in newNotifications but not in previousNotifications |
| 7 | */ |
| 8 | export function getNewNotifications( |
| 9 | previousAccountNotifications: AccountNotifications[], |
| 10 | newAccountNotifications: AccountNotifications[], |
| 11 | ): GitifyNotification[] { |
| 12 | return newAccountNotifications.flatMap((accountNotifications) => { |
| 13 | const accountPreviousNotifications = previousAccountNotifications.find( |
| 14 | (item) => |
| 15 | getAccountUUID(item.account) === |
| 16 | getAccountUUID(accountNotifications.account), |
| 17 | ); |
| 18 | |
| 19 | if (!accountPreviousNotifications) { |
| 20 | return accountNotifications.notifications; |
| 21 | } |
| 22 | |
| 23 | const previousIds = new Set( |
| 24 | accountPreviousNotifications.notifications.map((item) => item.id), |
| 25 | ); |
| 26 | |
| 27 | return accountNotifications.notifications.filter( |
| 28 | (notification) => !previousIds.has(notification.id), |
| 29 | ); |
| 30 | }); |
| 31 | } |
no test coverage detected