From 7bb462293bb775937067bd8ba20fc31a4854a266 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 8 Oct 2025 11:41:52 -0700 Subject: [PATCH] refactor: sonar issue reduce -> flatMap Signed-off-by: Adam Setch --- src/renderer/utils/notifications/native.ts | 42 +++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/renderer/utils/notifications/native.ts b/src/renderer/utils/notifications/native.ts index 86d14c3dd..197126696 100644 --- a/src/renderer/utils/notifications/native.ts +++ b/src/renderer/utils/notifications/native.ts @@ -10,31 +10,29 @@ export const triggerNativeNotifications = ( newNotifications: AccountNotifications[], state: GitifyState, ) => { - const diffNotifications = newNotifications - .map((accountNotifications) => { - const accountPreviousNotifications = previousNotifications.find( - (item) => - getAccountUUID(item.account) === - getAccountUUID(accountNotifications.account), - ); + const diffNotifications = newNotifications.flatMap((accountNotifications) => { + const accountPreviousNotifications = previousNotifications.find( + (item) => + getAccountUUID(item.account) === + getAccountUUID(accountNotifications.account), + ); - if (!accountPreviousNotifications) { - return accountNotifications.notifications; - } + if (!accountPreviousNotifications) { + return accountNotifications.notifications; + } - const accountPreviousNotificationsIds = new Set( - accountPreviousNotifications.notifications.map((item) => item.id), - ); + const accountPreviousNotificationsIds = new Set( + accountPreviousNotifications.notifications.map((item) => item.id), + ); - const accountNewNotifications = accountNotifications.notifications.filter( - (item) => { - return !accountPreviousNotificationsIds.has(`${item.id}`); - }, - ); + const accountNewNotifications = accountNotifications.notifications.filter( + (item) => { + return !accountPreviousNotificationsIds.has(`${item.id}`); + }, + ); - return accountNewNotifications; - }) - .reduce((acc, val) => acc.concat(val), []); + return accountNewNotifications; + }); setTrayIconColor(newNotifications); @@ -63,7 +61,7 @@ export const raiseNativeNotification = (notifications: Notification[]) => { ? '' : notification.repository.full_name; body = notification.subject.title; - // TODO FIXME = set url to notification url + // url intentionally left null (no direct subject URL available) } else { title = APPLICATION.NAME; body = `You have ${notifications.length} notifications`;