Skip to content

Commit 9d4e5f5

Browse files
committed
refactor(ads): update ad frequency logic and remove placeholder URLs
- Update ad frequency determination based on user role - Remove placeholder URLs from feed decorators - Simplify ad injection logic by using default values when no config is found
1 parent 65e1dd5 commit 9d4e5f5

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

lib/shared/services/feed_decorator_service.dart

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,20 @@ class FeedDecoratorService {
304304
title: 'Upgrade to Premium',
305305
description: 'Unlock unlimited access to all features and content.',
306306
ctaText: 'Upgrade Now',
307-
ctaUrl: '/upgrade', // Placeholder URL
307+
ctaUrl: '/upgrade',
308308
),
309309
FeedDecoratorType.rateApp: (
310310
title: 'Enjoying the App?',
311311
description: 'Let us know what you think by leaving a rating.',
312312
ctaText: 'Rate App',
313-
ctaUrl: '/rate-app', // Placeholder URL
313+
ctaUrl: '/rate-app',
314314
),
315315
FeedDecoratorType.enableNotifications: (
316316
title: 'Stay Up to Date',
317317
description:
318318
'Enable notifications to get the latest headlines delivered to you.',
319319
ctaText: 'Enable',
320-
ctaUrl: '/enable-notifications', // Placeholder URL
320+
ctaUrl: '/enable-notifications',
321321
),
322322
};
323323

@@ -427,23 +427,14 @@ class FeedDecoratorService {
427427
final userRole = user?.appRole ?? AppUserRole.guestUser;
428428

429429
// Determine ad frequency rules based on user role.
430-
final (adFrequency, adPlacementInterval) = switch (userRole) {
431-
AppUserRole.guestUser => (
432-
adConfig.feedAdConfiguration.frequencyConfig.guestAdFrequency,
433-
adConfig.feedAdConfiguration.frequencyConfig.guestAdPlacementInterval,
434-
),
435-
AppUserRole.standardUser => (
436-
adConfig.feedAdConfiguration.frequencyConfig.authenticatedAdFrequency,
437-
adConfig
438-
.feedAdConfiguration
439-
.frequencyConfig
440-
.authenticatedAdPlacementInterval,
441-
),
442-
AppUserRole.premiumUser => (
443-
adConfig.feedAdConfiguration.frequencyConfig.premiumAdFrequency,
444-
adConfig.feedAdConfiguration.frequencyConfig.premiumAdPlacementInterval,
445-
),
446-
};
430+
// Retrieve FeedAdFrequencyConfig from the visibleTo map.
431+
final feedAdFrequencyConfig =
432+
adConfig.feedAdConfiguration.visibleTo[userRole];
433+
434+
// Default to 0 for adFrequency and adPlacementInterval if no config is found
435+
// for the user role, effectively disabling ads for that role.
436+
final adFrequency = feedAdFrequencyConfig?.adFrequency ?? 0;
437+
final adPlacementInterval = feedAdFrequencyConfig?.adPlacementInterval ?? 0;
447438

448439
// If ad frequency is zero or less, no ads should be injected.
449440
if (adFrequency <= 0) {

0 commit comments

Comments
 (0)