Skip to content

Commit 4281410

Browse files
committed
feat(limitation): add saved filter limit check to ContentLimitationService
Extends the `ContentLimitationService` to enforce limits on saving new filters. This change adds a `saveFilter` case to the `ContentAction` enum and implements the corresponding logic within the `checkAction` method. It reads the user's role and the number of currently saved filters, comparing it against the role-specific limit defined in the remote configuration (`guestSavedFiltersLimit`, `authenticatedSavedFiltersLimit`, `premiumSavedFiltersLimit`). This centralizes the business rule for filter limits, ensuring it can be applied consistently across the app.
1 parent 854b967 commit 4281410

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/shared/services/content_limitation_service.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ enum ContentAction {
1515

1616
/// The action of following a country.
1717
followCountry,
18+
19+
/// The action of saving a filter.
20+
saveFilter,
1821
}
1922

2023
/// Defines the outcome of a content limitation check.
@@ -82,6 +85,21 @@ class ContentLimitationService {
8285
return _getLimitationStatusForRole(role);
8386
}
8487

88+
// Check if the user has reached the limit for saving filters.
89+
case ContentAction.saveFilter:
90+
final count = preferences.savedFilters.length;
91+
final int limit;
92+
switch (role) {
93+
case AppUserRole.guestUser:
94+
limit = limits.guestSavedFiltersLimit;
95+
case AppUserRole.standardUser:
96+
limit = limits.authenticatedSavedFiltersLimit;
97+
case AppUserRole.premiumUser:
98+
limit = limits.premiumSavedFiltersLimit;
99+
}
100+
if (count >= limit) {
101+
return _getLimitationStatusForRole(role);
102+
}
85103
case ContentAction.followTopic:
86104
case ContentAction.followSource:
87105
case ContentAction.followCountry:
@@ -107,6 +125,9 @@ class ContentLimitationService {
107125
case ContentAction.bookmarkHeadline:
108126
// This case is handled above and will not be reached here.
109127
count = 0;
128+
case ContentAction.saveFilter:
129+
// This case is handled above and will not be reached here.
130+
count = 0;
110131
}
111132

112133
if (count >= limit) {

0 commit comments

Comments
 (0)