Skip to content

Commit 6c8f37b

Browse files
authored
Merge pull request #71 from GetStream/fix-issue-70
fix: Follow model
2 parents 65c0411 + 438fd3f commit 6c8f37b

File tree

12 files changed

+196
-77
lines changed

12 files changed

+196
-77
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ await client.batch.addToMany(activityTarget, feeds!);
184184
185185
// Batch create follow relations (let flat:1 follow user:1, user:2 and user:3 feeds in one single request)
186186
const follows = [
187-
Follow('flat:1', 'user:1'),
188-
Follow('flat:1', 'user:2'),
189-
Follow('flat:1', 'user:3'),
187+
FollowRelation(source: 'flat:1', target: 'user:1'),
188+
FollowRelation(source:'flat:1', target: 'user:2'),
189+
FollowRelation(source:'flat:1', target: 'user:3'),
190190
];
191191
192192
// ⚠️ server-side only!

packages/stream_feed/lib/src/client/batch_operations_client.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:stream_feed/src/core/models/activity.dart';
33
import 'package:stream_feed/src/core/models/enriched_activity.dart';
44
import 'package:stream_feed/src/core/models/feed_id.dart';
55
import 'package:stream_feed/src/core/models/follow.dart';
6+
import 'package:stream_feed/src/core/models/follow_relation.dart';
67
import 'package:stream_feed/src/core/models/foreign_id_time_pair.dart';
78
import 'package:stream_feed/src/core/util/default.dart';
89
import 'package:stream_feed/src/core/util/token_helper.dart';
@@ -35,7 +36,7 @@ class BatchOperationsClient {
3536
/// API docs: [add_many_activities](https://getstream.io/activity-feeds/docs/flutter-dart/add_many_activities/?language=dart#batch-follow)
3637
///
3738
Future<void> followMany(
38-
Iterable<Follow> follows, {
39+
Iterable<FollowRelation> follows, {
3940
int? activityCopyLimit,
4041
}) {
4142
final token = TokenHelper.buildFollowToken(secret, TokenAction.write);
@@ -54,14 +55,14 @@ class BatchOperationsClient {
5455
/// API docs : [batch-unfollow](https://getstream.io/activity-feeds/docs/flutter-dart/add_many_activities/?language=dart#batch-unfollow)
5556
///
5657
Future<void> unfollowMany(
57-
Iterable<Follow> unfollows, {
58+
Iterable<UnFollowRelation> unfollows, {
5859
// TODO: seems to be Iterable<UnFollow> unfollows here
5960
required bool keepHistory,
6061
}) {
6162
final token = TokenHelper.buildFollowToken(secret, TokenAction.write);
6263
return _batch.unfollowMany(
6364
token,
64-
unfollows.map((e) => UnFollow.fromFollow(e, keepHistory)),
65+
unfollows.map((e) => UnFollowRelation.fromFollow(e, keepHistory)),
6566
);
6667
}
6768

packages/stream_feed/lib/src/core/api/batch_api.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:stream_feed/src/core/models/activity.dart';
77
import 'package:stream_feed/src/core/models/enriched_activity.dart';
88
import 'package:stream_feed/src/core/models/feed_id.dart';
99
import 'package:stream_feed/src/core/models/follow.dart';
10+
import 'package:stream_feed/src/core/models/follow_relation.dart';
1011
import 'package:stream_feed/src/core/models/foreign_id_time_pair.dart';
1112
import 'package:stream_feed/src/core/util/extension.dart';
1213
import 'package:stream_feed/src/core/util/routes.dart';
@@ -31,8 +32,8 @@ class BatchAPI {
3132
);
3233
}
3334

34-
Future<Response> followMany(
35-
Token token, int activityCopyLimit, Iterable<Follow> follows) async {
35+
Future<Response> followMany(Token token, int activityCopyLimit,
36+
Iterable<FollowRelation> follows) async {
3637
checkArgument(
3738
activityCopyLimit >= 0, 'Activity copy limit must be non negative');
3839

@@ -46,7 +47,7 @@ class BatchAPI {
4647
}
4748

4849
Future<Response> unfollowMany(
49-
Token token, Iterable<UnFollow> unfollows) async {
50+
Token token, Iterable<UnFollowRelation> unfollows) async {
5051
checkArgument(unfollows.isNotEmpty, 'No feeds to unfollow');
5152
return _client.post(
5253
Routes.unfollowManyUrl,

packages/stream_feed/lib/src/core/models/follow.dart

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,32 @@ part 'follow.g.dart';
77
@JsonSerializable()
88
class Follow extends Equatable {
99
///
10-
const Follow(this.source, this.target);
10+
const Follow({
11+
required this.feedId,
12+
required this.targetId,
13+
required this.createdAt,
14+
required this.updatedAt,
15+
});
1116

1217
/// Create a new instance from a json
1318
factory Follow.fromJson(Map<String, dynamic> json) => _$FollowFromJson(json);
1419

1520
/// The combination of feed slug and user id separated by a colon
1621
///For example: flat:1
17-
final String? source;
22+
final String feedId;
1823

1924
/// the id of the feed you want to follow
20-
final String? target;
25+
final String targetId;
2126

22-
@override
23-
List<Object?> get props => [source, target];
24-
25-
/// Serialize to json
26-
Map<String, dynamic> toJson() => _$FollowToJson(this);
27-
}
27+
///Date at which the follow relationship was created
28+
final DateTime createdAt;
2829

29-
///
30-
@JsonSerializable()
31-
class UnFollow extends Follow {
32-
///
33-
const UnFollow(String? source, String? target, this.keepHistory)
34-
: super(source, target);
35-
36-
/// Create a new instance from a json
37-
factory UnFollow.fromJson(Map<String, dynamic> json) =>
38-
_$UnFollowFromJson(json);
39-
40-
///
41-
factory UnFollow.fromFollow(Follow follow, bool? keepHistory) =>
42-
UnFollow(follow.source, follow.target, keepHistory);
43-
44-
/// when provided the activities from target feed
45-
/// will not be kept in the feed.
46-
final bool? keepHistory;
30+
///Date at which the follow relationship was updated
31+
final DateTime updatedAt;
4732

4833
@override
49-
List<Object?> get props => [...super.props, keepHistory];
34+
List<Object?> get props => [feedId, targetId, createdAt, updatedAt];
5035

5136
/// Serialize to json
52-
@override
53-
Map<String, dynamic> toJson() => _$UnFollowToJson(this);
37+
Map<String, dynamic> toJson() => _$FollowToJson(this);
5438
}

packages/stream_feed/lib/src/core/models/follow.g.dart

Lines changed: 8 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:json_annotation/json_annotation.dart';
3+
4+
part 'follow_relation.g.dart';
5+
6+
///
7+
@JsonSerializable()
8+
class FollowRelation extends Equatable {
9+
///
10+
const FollowRelation({required this.source, required this.target});
11+
12+
/// Create a new instance from a json
13+
factory FollowRelation.fromJson(Map<String, dynamic> json) =>
14+
_$FollowRelationFromJson(json);
15+
16+
/// The combination of feed slug and user id separated by a colon
17+
///For example: flat:1
18+
final String source;
19+
20+
/// the id of the feed you want to follow
21+
final String target;
22+
23+
@override
24+
List<Object?> get props => [source, target];
25+
26+
/// Serialize to json
27+
Map<String, dynamic> toJson() => _$FollowRelationToJson(this);
28+
}
29+
30+
///
31+
@JsonSerializable()
32+
class UnFollowRelation extends FollowRelation {
33+
///
34+
const UnFollowRelation(
35+
{required String source, required String target, this.keepHistory})
36+
: super(source: source, target: target);
37+
38+
/// Create a new instance from a json
39+
factory UnFollowRelation.fromJson(Map<String, dynamic> json) =>
40+
_$UnFollowRelationFromJson(json);
41+
42+
///
43+
factory UnFollowRelation.fromFollow(
44+
FollowRelation follow, bool? keepHistory) =>
45+
UnFollowRelation(
46+
source: follow.source,
47+
target: follow.target,
48+
keepHistory: keepHistory);
49+
50+
/// when provided the activities from target feed
51+
/// will not be kept in the feed.
52+
final bool? keepHistory;
53+
54+
@override
55+
List<Object?> get props => [...super.props, keepHistory];
56+
57+
/// Serialize to json
58+
@override
59+
Map<String, dynamic> toJson() => _$UnFollowRelationToJson(this);
60+
}

packages/stream_feed/lib/src/core/models/follow_relation.g.dart

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_feed/test/feed_api_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ Future<void> main() async {
144144
)).thenAnswer((_) async => Response(
145145
data: {
146146
'results': [
147-
{'feed_id': 'feedId', 'target_id': 'targetId'}
147+
{
148+
'feed_id': 'feedId',
149+
'target_id': 'targetId',
150+
'created_at': '2021-05-14T19:58:27.274792063Z',
151+
'updated_at': '2021-05-14T19:58:27.274792063Z'
152+
}
148153
]
149154
},
150155
requestOptions: RequestOptions(

packages/stream_feed/test/feed_client_test.dart

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:mocktail/mocktail.dart';
33
import 'package:stream_feed/src/client/feed.dart';
44
import 'package:stream_feed/src/client/flat_feed.dart';
55
import 'package:stream_feed/src/core/http/token.dart';
6+
import 'package:stream_feed/src/core/models/follow_relation.dart';
67
import 'package:stream_feed/src/core/models/follow_stats.dart';
78
import 'package:stream_feed/src/core/models/followers.dart';
89
import 'package:stream_feed/src/core/models/following.dart';
@@ -63,10 +64,10 @@ void main() {
6364
});
6465

6566
test('follows', () {
66-
final follows = <Follow>[
67-
const Follow('timeline:1', 'user:1'),
68-
const Follow('timeline:1', 'user:2'),
69-
const Follow('timeline:1', 'user:3'),
67+
final follows = <FollowRelation>[
68+
const FollowRelation(source: 'timeline:1', target: 'user:1'),
69+
const FollowRelation(source: 'timeline:1', target: 'user:2'),
70+
const FollowRelation(source: 'timeline:1', target: 'user:3'),
7071
];
7172
expect(follows.map((e) => e.toJson()), [
7273
{'source': 'timeline:1', 'target': 'user:1'},
@@ -99,10 +100,18 @@ void main() {
99100
const offset = 0;
100101
final feed = FeedId('slug', 'userId');
101102
final feedIds = [FeedId('slug', 'userId')];
103+
final date = DateTime.parse("2021-05-14T19:58:27.274792063Z");
102104
final follows = <Follow>[
103-
const Follow('timeline:1', 'user:1'),
104-
const Follow('timeline:1', 'user:2'),
105-
const Follow('timeline:1', 'user:3'),
105+
Follow(
106+
feedId: 'timeline:1',
107+
targetId: 'user:1',
108+
createdAt: date,
109+
updatedAt: date),
110+
Follow(
111+
feedId: 'timeline:1',
112+
targetId: 'user:2',
113+
createdAt: date,
114+
updatedAt: date),
106115
];
107116
when(() => api.following(token, feed, limit, offset, feedIds))
108117
.thenAnswer((_) async => follows);
@@ -116,10 +125,18 @@ void main() {
116125
const offset = 0;
117126
final feed = FeedId('slug', 'userId');
118127
final feedIds = [FeedId('slug', 'userId')];
128+
final date = DateTime.parse("2021-05-14T19:58:27.274792063Z");
119129
final follows = <Follow>[
120-
const Follow('timeline:1', 'user:1'),
121-
const Follow('timeline:1', 'user:2'),
122-
const Follow('timeline:1', 'user:3'),
130+
Follow(
131+
feedId: 'timeline:1',
132+
targetId: 'user:1',
133+
createdAt: date,
134+
updatedAt: date),
135+
Follow(
136+
feedId: 'timeline:1',
137+
targetId: 'user:2',
138+
createdAt: date,
139+
updatedAt: date),
123140
];
124141
when(() => api.followers(token, feed, limit, offset, feedIds))
125142
.thenAnswer((_) async => follows);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2-
"source": "feedId",
3-
"target": "targetId"
2+
"feed_id": "feedId",
3+
"target_id": "targetId",
4+
"created_at": "2021-05-14T19:58:27.274792063Z",
5+
"updated_at": "2021-05-14T19:58:27.274792063Z"
46
}

0 commit comments

Comments
 (0)