Skip to content

Commit

Permalink
fix: change filter logic to avoid early returning (#1852)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy authored Feb 25, 2025
1 parent 6702763 commit da58488
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/renderer/utils/notifications/filters/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,43 @@ export function filterNotifications(
settings: SettingsState,
): Notification[] {
return notifications.filter((notification) => {
let passesFilters = true;

if (settings.detailedNotifications) {
if (hasUserTypeFilters(settings)) {
return settings.filterUserTypes.some((userType) =>
filterNotificationByUserType(notification, userType),
);
passesFilters =
passesFilters &&
settings.filterUserTypes.some((userType) =>
filterNotificationByUserType(notification, userType),
);
}

if (hasIncludeHandleFilters(settings)) {
return settings.filterIncludeHandles.some((handle) =>
filterNotificationByHandle(notification, handle),
);
passesFilters =
passesFilters &&
settings.filterIncludeHandles.some((handle) =>
filterNotificationByHandle(notification, handle),
);
}

if (hasExcludeHandleFilters(settings)) {
return !settings.filterExcludeHandles.some((handle) =>
filterNotificationByHandle(notification, handle),
);
passesFilters =
passesFilters &&
!settings.filterExcludeHandles.some((handle) =>
filterNotificationByHandle(notification, handle),
);
}
}

if (hasReasonFilters(settings)) {
return settings.filterReasons.some((reason) =>
filterNotificationByReason(notification, reason),
);
passesFilters =
passesFilters &&
settings.filterReasons.some((reason) =>
filterNotificationByReason(notification, reason),
);
}

return true;
return passesFilters;
});
}

Expand Down

0 comments on commit da58488

Please sign in to comment.