1+ import 'package:equatable/equatable.dart' ;
12import 'package:ht_shared/ht_shared.dart' show FeedItem;
23import 'package:ht_shared/src/models/content_type.dart' ;
34import 'package:ht_shared/src/models/feed/feed.dart' show FeedItem;
45import 'package:ht_shared/src/models/feed/feed_item.dart' show FeedItem;
56import 'package:ht_shared/src/models/models.dart' show FeedItem;
7+ // Removed redundant FeedItem imports
68import 'package:json_annotation/json_annotation.dart' ;
79
810part 'feed_item_action.g.dart' ;
@@ -15,12 +17,20 @@ part 'feed_item_action.g.dart';
1517/// matching in the UI layer.
1618/// {@endtemplate}
1719@JsonSerializable (createFactory: false )
18- sealed class FeedItemAction {
20+ sealed class FeedItemAction extends Equatable {
1921 /// {@macro feed_item_action}
20- const FeedItemAction ();
22+ const FeedItemAction ({required this .type});
23+
24+ /// A string representation of the action type.
25+ // This 'type' field is crucial for deserialization and Equatable.
26+ @JsonKey (name: 'type' , required : true )
27+ final String type;
2128
2229 /// Converts this [FeedItemAction] instance to a JSON map.
2330 Map <String , dynamic > toJson ();
31+
32+ @override
33+ List <Object ?> get props => [type];
2434}
2535
2636/// Helper function to deserialize a JSON map into a [FeedItemAction] instance.
@@ -63,24 +73,28 @@ class OpenInternalContent extends FeedItemAction {
6373 const OpenInternalContent ({
6474 required this .contentId,
6575 required this .contentType,
66- }) : type = 'open_internal_content' ;
76+ }) : super ( type: 'open_internal_content' ) ;
6777
6878 /// Factory method to create an [OpenInternalContent] instance from a JSON map.
6979 factory OpenInternalContent .fromJson (Map <String , dynamic > json) =>
7080 _$OpenInternalContentFromJson (json);
7181
72- /// A string representation of the action type.
73- @JsonKey (name: 'type' , required : true )
74- final String type;
75-
7682 /// The unique identifier of the internal content to open.
7783 final String contentId;
7884
7985 /// The type of the internal content (e.g., headline, category, source).
8086 final ContentType contentType;
8187
8288 @override
83- Map <String , dynamic > toJson () => _$OpenInternalContentToJson (this );
89+ Map <String , dynamic > toJson () {
90+ final json = _$OpenInternalContentToJson (this );
91+ json['type' ] =
92+ type; // Ensure type is included, though super.type should exist
93+ return json;
94+ }
95+
96+ @override
97+ List <Object ?> get props => [...super .props, contentId, contentType];
8498}
8599
86100/// {@template show_interstitial_then_open_internal_content}
@@ -92,7 +106,7 @@ class ShowInterstitialThenOpenInternalContent extends FeedItemAction {
92106 const ShowInterstitialThenOpenInternalContent ({
93107 required this .contentId,
94108 required this .contentType,
95- }) : type = 'show_interstitial_then_open_internal_content' ;
109+ }) : super ( type: 'show_interstitial_then_open_internal_content' ) ;
96110
97111 /// Factory method to create a [ShowInterstitialThenOpenInternalContent]
98112 /// instance from a JSON map.
@@ -101,19 +115,21 @@ class ShowInterstitialThenOpenInternalContent extends FeedItemAction {
101115 ) =>
102116 _$ShowInterstitialThenOpenInternalContentFromJson (json);
103117
104- /// A string representation of the action type.
105- @JsonKey (name: 'type' , required : true )
106- final String type;
107-
108118 /// The unique identifier of the internal content to open after the interstitial.
109119 final String contentId;
110120
111121 /// The type of the internal content (e.g., headline, category, source).
112122 final ContentType contentType;
113123
114124 @override
115- Map <String , dynamic > toJson () =>
116- _$ShowInterstitialThenOpenInternalContentToJson (this );
125+ Map <String , dynamic > toJson () {
126+ final json = _$ShowInterstitialThenOpenInternalContentToJson (this );
127+ json['type' ] = type;
128+ return json;
129+ }
130+
131+ @override
132+ List <Object ?> get props => [...super .props, contentId, contentType];
117133}
118134
119135/// {@template open_external_url}
@@ -122,19 +138,22 @@ class ShowInterstitialThenOpenInternalContent extends FeedItemAction {
122138@JsonSerializable ()
123139class OpenExternalUrl extends FeedItemAction {
124140 /// {@macro open_external_url}
125- const OpenExternalUrl ({required this .url}) : type = 'open_external_url' ;
141+ const OpenExternalUrl ({required this .url}) : super ( type: 'open_external_url' ) ;
126142
127143 /// Factory method to create an [OpenExternalUrl] instance from a JSON map.
128144 factory OpenExternalUrl .fromJson (Map <String , dynamic > json) =>
129145 _$OpenExternalUrlFromJson (json);
130146
131- /// A string representation of the action type.
132- @JsonKey (name: 'type' , required : true )
133- final String type;
134-
135147 /// The URL to open.
136148 final String url;
137149
138150 @override
139- Map <String , dynamic > toJson () => _$OpenExternalUrlToJson (this );
151+ Map <String , dynamic > toJson () {
152+ final json = _$OpenExternalUrlToJson (this );
153+ json['type' ] = type;
154+ return json;
155+ }
156+
157+ @override
158+ List <Object ?> get props => [...super .props, url];
140159}
0 commit comments