|
1 | 1 | import 'package:core/core.dart'; |
2 | 2 | import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart'; |
3 | 3 |
|
4 | | - |
5 | 4 | /// Defines the specific type of content-related action a user is trying to |
6 | 5 | /// perform, which may be subject to limitations. |
7 | 6 | enum ContentAction { |
@@ -33,7 +32,6 @@ enum LimitationStatus { |
33 | 32 | premiumUserLimitReached, |
34 | 33 | } |
35 | 34 |
|
36 | | - |
37 | 35 | /// {@template content_limitation_service} |
38 | 36 | /// A service that centralizes the logic for checking if a user can perform |
39 | 37 | /// a content-related action based on their role and remote configuration limits. |
@@ -65,35 +63,53 @@ class ContentLimitationService { |
65 | 63 | return LimitationStatus.allowed; |
66 | 64 | } |
67 | 65 |
|
68 | | - final limits = remoteConfig.contentConfiguration; |
| 66 | + final limits = remoteConfig.userPreferenceConfig; |
69 | 67 | final role = user.appRole; |
70 | 68 |
|
71 | 69 | switch (action) { |
72 | 70 | case ContentAction.bookmarkHeadline: |
73 | 71 | final count = preferences.savedHeadlines.length; |
74 | | - final limit = limits.savedHeadlinesLimit[role]; |
75 | | - if (limit != null && count >= limit) { |
| 72 | + final int limit; |
| 73 | + switch (role) { |
| 74 | + case AppUserRole.guestUser: |
| 75 | + limit = limits.guestSavedHeadlinesLimit; |
| 76 | + case AppUserRole.standardUser: |
| 77 | + limit = limits.authenticatedSavedHeadlinesLimit; |
| 78 | + case AppUserRole.premiumUser: |
| 79 | + limit = limits.premiumSavedHeadlinesLimit; |
| 80 | + } |
| 81 | + if (count >= limit) { |
76 | 82 | return _getLimitationStatusForRole(role); |
77 | 83 | } |
78 | 84 |
|
79 | 85 | case ContentAction.followTopic: |
80 | | - final count = preferences.followedTopics.length; |
81 | | - final limit = limits.followedTopicsLimit[role]; |
82 | | - if (limit != null && count >= limit) { |
83 | | - return _getLimitationStatusForRole(role); |
| 86 | + case ContentAction.followSource: |
| 87 | + case ContentAction.followCountry: |
| 88 | + final int limit; |
| 89 | + switch (role) { |
| 90 | + case AppUserRole.guestUser: |
| 91 | + limit = limits.guestFollowedItemsLimit; |
| 92 | + case AppUserRole.standardUser: |
| 93 | + limit = limits.authenticatedFollowedItemsLimit; |
| 94 | + case AppUserRole.premiumUser: |
| 95 | + limit = limits.premiumFollowedItemsLimit; |
84 | 96 | } |
85 | 97 |
|
86 | | - case ContentAction.followSource: |
87 | | - final count = preferences.followedSources.length; |
88 | | - final limit = limits.followedSourcesLimit[role]; |
89 | | - if (limit != null && count >= limit) { |
90 | | - return _getLimitationStatusForRole(role); |
| 98 | + // Determine the count for the specific item type being followed. |
| 99 | + final int count; |
| 100 | + switch (action) { |
| 101 | + case ContentAction.followTopic: |
| 102 | + count = preferences.followedTopics.length; |
| 103 | + case ContentAction.followSource: |
| 104 | + count = preferences.followedSources.length; |
| 105 | + case ContentAction.followCountry: |
| 106 | + count = preferences.followedCountries.length; |
| 107 | + case ContentAction.bookmarkHeadline: |
| 108 | + // This case is handled above and will not be reached here. |
| 109 | + count = 0; |
91 | 110 | } |
92 | 111 |
|
93 | | - case ContentAction.followCountry: |
94 | | - final count = preferences.followedCountries.length; |
95 | | - final limit = limits.followedCountriesLimit[role]; |
96 | | - if (limit != null && count >= limit) { |
| 112 | + if (count >= limit) { |
97 | 113 | return _getLimitationStatusForRole(role); |
98 | 114 | } |
99 | 115 | } |
|
0 commit comments