Skip to content

Commit 633d9f3

Browse files
authored
refactor: sonar issue reduce -> flatMap (#2281)
Signed-off-by: Adam Setch <[email protected]>
1 parent e719675 commit 633d9f3

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/renderer/utils/notifications/native.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,29 @@ export const triggerNativeNotifications = (
1010
newNotifications: AccountNotifications[],
1111
state: GitifyState,
1212
) => {
13-
const diffNotifications = newNotifications
14-
.map((accountNotifications) => {
15-
const accountPreviousNotifications = previousNotifications.find(
16-
(item) =>
17-
getAccountUUID(item.account) ===
18-
getAccountUUID(accountNotifications.account),
19-
);
13+
const diffNotifications = newNotifications.flatMap((accountNotifications) => {
14+
const accountPreviousNotifications = previousNotifications.find(
15+
(item) =>
16+
getAccountUUID(item.account) ===
17+
getAccountUUID(accountNotifications.account),
18+
);
2019

21-
if (!accountPreviousNotifications) {
22-
return accountNotifications.notifications;
23-
}
20+
if (!accountPreviousNotifications) {
21+
return accountNotifications.notifications;
22+
}
2423

25-
const accountPreviousNotificationsIds = new Set<string>(
26-
accountPreviousNotifications.notifications.map((item) => item.id),
27-
);
24+
const accountPreviousNotificationsIds = new Set<string>(
25+
accountPreviousNotifications.notifications.map((item) => item.id),
26+
);
2827

29-
const accountNewNotifications = accountNotifications.notifications.filter(
30-
(item) => {
31-
return !accountPreviousNotificationsIds.has(`${item.id}`);
32-
},
33-
);
28+
const accountNewNotifications = accountNotifications.notifications.filter(
29+
(item) => {
30+
return !accountPreviousNotificationsIds.has(`${item.id}`);
31+
},
32+
);
3433

35-
return accountNewNotifications;
36-
})
37-
.reduce((acc, val) => acc.concat(val), []);
34+
return accountNewNotifications;
35+
});
3836

3937
setTrayIconColor(newNotifications);
4038

@@ -63,7 +61,7 @@ export const raiseNativeNotification = (notifications: Notification[]) => {
6361
? ''
6462
: notification.repository.full_name;
6563
body = notification.subject.title;
66-
// TODO FIXME = set url to notification url
64+
// url intentionally left null (no direct subject URL available)
6765
} else {
6866
title = APPLICATION.NAME;
6967
body = `You have ${notifications.length} notifications`;

0 commit comments

Comments
 (0)