@@ -26,9 +26,14 @@ class UserAppSettings extends Equatable {
2626 DisplaySettings ? displaySettings,
2727 AppLanguage ? language,
2828 FeedDisplayPreferences ? feedPreferences,
29+ Map <String , int >? engagementShownCounts,
30+ Map <String , DateTime >? engagementLastShownTimestamps,
2931 }) : displaySettings = displaySettings ?? const DisplaySettings (),
3032 language = language ?? 'en' , // Default language is English
31- feedPreferences = feedPreferences ?? const FeedDisplayPreferences ();
33+ feedPreferences = feedPreferences ?? const FeedDisplayPreferences (),
34+ engagementShownCounts = engagementShownCounts ?? const {},
35+ engagementLastShownTimestamps =
36+ engagementLastShownTimestamps ?? const {};
3237
3338 /// Factory method to create a [UserAppSettings] instance from a JSON map.
3439 factory UserAppSettings .fromJson (Map <String , dynamic > json) =>
@@ -46,11 +51,30 @@ class UserAppSettings extends Equatable {
4651 /// User-configurable settings for how content feeds are displayed.
4752 final FeedDisplayPreferences feedPreferences;
4853
54+ /// A map tracking how many times each engagement type has been shown to the user.
55+ /// Key: EngagementTemplateType.name (string), Value: count.
56+ final Map <String , int > engagementShownCounts;
57+
58+ /// A map tracking the last time each engagement type was shown to the user.
59+ /// Key: EngagementTemplateType.name (string), Value: timestamp.
60+ @JsonKey (
61+ fromJson: _engagementLastShownTimestampsFromJson,
62+ toJson: _engagementLastShownTimestampsToJson,
63+ )
64+ final Map <String , DateTime > engagementLastShownTimestamps;
65+
4966 /// Converts this [UserAppSettings] instance to a JSON map.
5067 Map <String , dynamic > toJson () => _$UserAppSettingsToJson (this );
5168
5269 @override
53- List <Object ?> get props => [id, displaySettings, language, feedPreferences];
70+ List <Object ?> get props => [
71+ id,
72+ displaySettings,
73+ language,
74+ feedPreferences,
75+ engagementShownCounts,
76+ engagementLastShownTimestamps,
77+ ];
5478
5579 /// Creates a copy of this [UserAppSettings] but with the given fields
5680 /// replaced with the new values.
@@ -59,12 +83,34 @@ class UserAppSettings extends Equatable {
5983 DisplaySettings ? displaySettings,
6084 AppLanguage ? language,
6185 FeedDisplayPreferences ? feedPreferences,
86+ Map <String , int >? engagementShownCounts,
87+ Map <String , DateTime >? engagementLastShownTimestamps,
6288 }) {
6389 return UserAppSettings (
6490 id: id ?? this .id,
6591 displaySettings: displaySettings ?? this .displaySettings,
6692 language: language ?? this .language,
6793 feedPreferences: feedPreferences ?? this .feedPreferences,
94+ engagementShownCounts:
95+ engagementShownCounts ?? this .engagementShownCounts,
96+ engagementLastShownTimestamps:
97+ engagementLastShownTimestamps ?? this .engagementLastShownTimestamps,
6898 );
6999 }
70100}
101+
102+ // Helper function for parsing Map<String, DateTime> from JSON
103+ Map <String , DateTime > _engagementLastShownTimestampsFromJson (
104+ Map <String , dynamic >? json,
105+ ) {
106+ if (json == null ) return const {};
107+ return json
108+ .map ((key, value) => MapEntry (key, DateTime .parse (value as String )));
109+ }
110+
111+ // Helper function for serializing Map<String, DateTime> to JSON
112+ Map <String , dynamic > _engagementLastShownTimestampsToJson (
113+ Map <String , DateTime > map,
114+ ) {
115+ return map.map ((key, value) => MapEntry (key, value.toIso8601String ()));
116+ }
0 commit comments