Line data Source code
1 : import 'package:equatable/equatable.dart';
2 : import 'package:json_annotation/json_annotation.dart';
3 : import 'package:stream_feed_dart/src/core/util/serializer.dart';
4 :
5 : import 'package:stream_feed_dart/src/core/models/feed_id.dart';
6 :
7 : part 'reaction.g.dart';
8 :
9 : ///
10 : @JsonSerializable()
11 : class Reaction extends Equatable {
12 : ///
13 7 : const Reaction({
14 : this.id,
15 : this.kind,
16 : this.activityId,
17 : this.userId,
18 : this.parent,
19 : this.createdAt,
20 : this.updatedAt,
21 : this.targetFeeds,
22 : this.user,
23 : this.targetFeedsExtraData,
24 : this.data,
25 : this.latestChildren,
26 : this.childrenCounts,
27 : });
28 :
29 : /// Create a new instance from a json
30 5 : factory Reaction.fromJson(Map<String, dynamic> json) =>
31 5 : _$ReactionFromJson(json);
32 :
33 : /// api will generate an id if it's missing
34 : @JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
35 : final String? id;
36 :
37 : /// required only for add/addChile, not update
38 : final String? kind;
39 :
40 : /// only required for reactions
41 : final String? activityId;
42 :
43 : /// optional when using client tokens
44 : final String? userId;
45 :
46 : /// only required for child reactions
47 : @JsonKey(includeIfNull: false)
48 : final String? parent;
49 :
50 : ///
51 : @JsonKey(includeIfNull: false)
52 : final DateTime? createdAt;
53 :
54 : ///
55 : @JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
56 : final DateTime? updatedAt;
57 :
58 : ///
59 : @JsonKey(includeIfNull: false, fromJson: FeedId.fromIds, toJson: FeedId.toIds)
60 : final List<FeedId>? targetFeeds;
61 :
62 : ///
63 : @JsonKey(includeIfNull: false)
64 : final Map<String, Object>? user;
65 :
66 : ///
67 : @JsonKey(includeIfNull: false)
68 : final Map<String, Object>? targetFeedsExtraData;
69 :
70 : ///
71 : @JsonKey(includeIfNull: false)
72 : final Map<String, Object>? data;
73 :
74 : ///
75 : @JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
76 : final Map<String, List<Reaction>>? latestChildren;
77 :
78 : ///
79 : @JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
80 : final Map<String, int>? childrenCounts;
81 :
82 : /// Known top level fields.
83 : /// Useful for [Serializer] methods.
84 : static const topLevelFields = [
85 : 'id',
86 : 'kind',
87 : 'activity_id',
88 : 'user_id',
89 : 'user',
90 : 'data',
91 : 'created_at',
92 : 'updated_at',
93 : 'parent',
94 : 'latest_children',
95 : 'children_counts',
96 : ];
97 :
98 : ///
99 1 : Reaction copyWith({
100 : String? id,
101 : String? kind,
102 : String? activityId,
103 : String? userId,
104 : String? parent,
105 : DateTime? createdAt,
106 : DateTime? updatedAt,
107 : List<FeedId>? targetFeeds,
108 : Map<String, Object>? user,
109 : Map<String, Object>? targetFeedsExtraData,
110 : Map<String, Object>? data,
111 : Map<String, List<Reaction>>? latestChildren,
112 : Map<String, int>? childrenCounts,
113 : }) =>
114 1 : Reaction(
115 1 : id: id ?? this.id,
116 1 : kind: kind ?? this.kind,
117 1 : activityId: activityId ?? this.activityId,
118 1 : userId: userId ?? this.userId,
119 1 : parent: parent ?? this.parent,
120 1 : createdAt: createdAt ?? this.createdAt,
121 1 : updatedAt: updatedAt ?? this.updatedAt,
122 1 : targetFeeds: targetFeeds ?? this.targetFeeds,
123 1 : user: user ?? this.user,
124 1 : targetFeedsExtraData: targetFeedsExtraData ?? this.targetFeedsExtraData,
125 0 : data: data ?? this.data,
126 1 : latestChildren: latestChildren ?? this.latestChildren,
127 1 : childrenCounts: childrenCounts ?? this.childrenCounts,
128 : );
129 :
130 5 : @override
131 5 : List<Object?> get props => [
132 5 : id,
133 5 : kind,
134 5 : activityId,
135 5 : userId,
136 5 : parent,
137 5 : createdAt,
138 5 : updatedAt,
139 5 : targetFeeds,
140 5 : user,
141 5 : targetFeedsExtraData,
142 5 : data,
143 5 : latestChildren,
144 5 : childrenCounts,
145 : ];
146 :
147 : /// Serialize to json
148 2 : Map<String, dynamic> toJson() => _$ReactionToJson(this);
149 : }
|