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 'activity.g.dart';
8 :
9 : ///
10 : @JsonSerializable()
11 : class Activity extends Equatable {
12 : ///
13 7 : const Activity({
14 : required this.actor,
15 : required this.verb,
16 : required this.object,
17 : this.id,
18 : this.foreignId,
19 : this.target,
20 : this.time,
21 : this.to,
22 : this.analytics,
23 : this.extraContext,
24 : this.origin,
25 : this.score,
26 : this.extraData,
27 : });
28 :
29 : /// Create a new instance from a json
30 5 : factory Activity.fromJson(Map<String, dynamic>? json) =>
31 10 : _$ActivityFromJson(Serializer.moveKeysToRoot(json, topLevelFields)!);
32 :
33 : ///
34 : @JsonKey(includeIfNull: false)
35 : final String? id;
36 :
37 : ///
38 : final String? actor;
39 :
40 : ///
41 : final String? verb;
42 :
43 : ///
44 : final String? object;
45 :
46 : ///
47 : @JsonKey(includeIfNull: false)
48 : final String? foreignId;
49 :
50 : ///
51 : @JsonKey(includeIfNull: false)
52 : final String? target;
53 :
54 : ///
55 : @JsonKey(includeIfNull: false)
56 : final DateTime? time;
57 :
58 : ///
59 : @JsonKey(includeIfNull: false)
60 : final String? origin;
61 :
62 : ///
63 : @JsonKey(
64 : includeIfNull: false,
65 : fromJson: FeedId.fromIds,
66 : toJson: FeedId.toIds,
67 : )
68 : final List<FeedId>? to;
69 :
70 : ///
71 : @JsonKey(includeIfNull: false)
72 : final double? score;
73 :
74 : ///
75 : @JsonKey(includeIfNull: false)
76 : final Map<String, Object>? analytics;
77 :
78 : ///
79 : @JsonKey(includeIfNull: false)
80 : final Map<String, Object>? extraContext;
81 :
82 : /// Map of custom user extraData
83 : @JsonKey(includeIfNull: false)
84 : final Map<String, Object>? extraData;
85 :
86 : /// Known top level fields.
87 : /// Useful for [Serializer] methods.
88 : static const topLevelFields = [
89 : 'actor',
90 : 'verb',
91 : 'object',
92 : 'id',
93 : 'foreign_id',
94 : 'target',
95 : 'time',
96 : 'to',
97 : 'analytics',
98 : 'extra_context',
99 : 'origin',
100 : 'score',
101 : ];
102 :
103 : /// Serialize to json
104 2 : Map<String, dynamic> toJson() =>
105 4 : Serializer.moveKeysToMapInPlace(_$ActivityToJson(this), topLevelFields);
106 :
107 : ///
108 1 : Activity copyWith({
109 : String? id,
110 : String? actor,
111 : String? verb,
112 : String? object,
113 : String? foreignId,
114 : String? target,
115 : DateTime? time,
116 : String? origin,
117 : List<FeedId>? to,
118 : double? score,
119 : Map<String, Object>? analytics,
120 : Map<String, Object>? extraContext,
121 : Map<String, Object>? extraData,
122 : }) =>
123 1 : Activity(
124 1 : id: id ?? this.id,
125 1 : actor: actor ?? this.actor,
126 1 : verb: verb ?? this.verb,
127 1 : object: object ?? this.object,
128 1 : foreignId: foreignId ?? this.foreignId,
129 1 : target: target ?? this.target,
130 1 : time: time ?? this.time,
131 1 : origin: origin ?? this.origin,
132 1 : to: to ?? this.to,
133 1 : score: score ?? this.score,
134 1 : analytics: analytics ?? this.analytics,
135 1 : extraContext: extraContext ?? this.extraContext,
136 0 : extraData: extraData ?? this.extraData,
137 : );
138 :
139 4 : @override
140 4 : List<Object?> get props => [
141 4 : actor,
142 4 : object,
143 4 : verb,
144 4 : target,
145 4 : to,
146 4 : foreignId,
147 4 : id,
148 4 : time,
149 4 : analytics,
150 4 : extraContext,
151 4 : origin,
152 4 : score,
153 4 : extraData,
154 : ];
155 : }
|