Skip to content

Commit da58488

Browse files
authored
fix: change filter logic to avoid early returning (#1852)
Signed-off-by: Adam Setch <[email protected]>
1 parent 6702763 commit da58488

File tree

1 file changed

+23
-13
lines changed
  • src/renderer/utils/notifications/filters

1 file changed

+23
-13
lines changed

src/renderer/utils/notifications/filters/filter.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,43 @@ export function filterNotifications(
1313
settings: SettingsState,
1414
): Notification[] {
1515
return notifications.filter((notification) => {
16+
let passesFilters = true;
17+
1618
if (settings.detailedNotifications) {
1719
if (hasUserTypeFilters(settings)) {
18-
return settings.filterUserTypes.some((userType) =>
19-
filterNotificationByUserType(notification, userType),
20-
);
20+
passesFilters =
21+
passesFilters &&
22+
settings.filterUserTypes.some((userType) =>
23+
filterNotificationByUserType(notification, userType),
24+
);
2125
}
2226

2327
if (hasIncludeHandleFilters(settings)) {
24-
return settings.filterIncludeHandles.some((handle) =>
25-
filterNotificationByHandle(notification, handle),
26-
);
28+
passesFilters =
29+
passesFilters &&
30+
settings.filterIncludeHandles.some((handle) =>
31+
filterNotificationByHandle(notification, handle),
32+
);
2733
}
2834

2935
if (hasExcludeHandleFilters(settings)) {
30-
return !settings.filterExcludeHandles.some((handle) =>
31-
filterNotificationByHandle(notification, handle),
32-
);
36+
passesFilters =
37+
passesFilters &&
38+
!settings.filterExcludeHandles.some((handle) =>
39+
filterNotificationByHandle(notification, handle),
40+
);
3341
}
3442
}
3543

3644
if (hasReasonFilters(settings)) {
37-
return settings.filterReasons.some((reason) =>
38-
filterNotificationByReason(notification, reason),
39-
);
45+
passesFilters =
46+
passesFilters &&
47+
settings.filterReasons.some((reason) =>
48+
filterNotificationByReason(notification, reason),
49+
);
4050
}
4151

42-
return true;
52+
return passesFilters;
4353
});
4454
}
4555

0 commit comments

Comments
 (0)