Skip to content

Commit c19ee5e

Browse files
authored
Merge pull request #185 from GetStream/copy_limit
[FEEDS-996]chore: add activity copy limit to follow
2 parents 7f8c7f5 + 93a7d56 commit c19ee5e

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/main/java/io/getstream/core/models/FollowRelation.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.getstream.core.models;
22

3+
import static com.google.common.base.Preconditions.checkArgument;
34
import static com.google.common.base.Preconditions.checkNotNull;
45

56
import com.fasterxml.jackson.annotation.JsonCreator;
67
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
import com.fasterxml.jackson.annotation.JsonInclude;
79
import com.fasterxml.jackson.annotation.JsonProperty;
810
import com.google.common.base.MoreObjects;
911
import java.util.Objects;
@@ -12,15 +14,28 @@
1214
public final class FollowRelation {
1315
private final String source;
1416
private final String target;
17+
private final Integer activityCopyLimit;
1518

1619
@JsonCreator
1720
public FollowRelation(
18-
@JsonProperty("feed_id") String source, @JsonProperty("target_id") String target) {
21+
@JsonProperty("feed_id") String source,
22+
@JsonProperty("target_id") String target,
23+
@JsonProperty("activity_copy_limit") Integer activityCopyLimit) {
1924
checkNotNull(source, "FollowRelation 'source' field required");
2025
checkNotNull(target, "FollowRelation 'target' field required");
26+
if (activityCopyLimit != null) {
27+
checkArgument(activityCopyLimit >= 0, "Activity copy limit must be non negative");
28+
}
2129

2230
this.source = source;
2331
this.target = target;
32+
this.activityCopyLimit = activityCopyLimit;
33+
}
34+
35+
public FollowRelation(
36+
@JsonProperty("feed_id") String source,
37+
@JsonProperty("target_id") String target) {
38+
this(source, target, null);
2439
}
2540

2641
public String getSource() {
@@ -31,24 +46,33 @@ public String getTarget() {
3146
return this.target;
3247
}
3348

49+
@JsonProperty("activity_copy_limit")
50+
@JsonInclude(JsonInclude.Include.NON_NULL)
51+
public Integer getActivityCopyLimit() {
52+
return this.activityCopyLimit;
53+
}
54+
3455
@Override
3556
public boolean equals(Object o) {
3657
if (this == o) return true;
3758
if (o == null || getClass() != o.getClass()) return false;
3859
FollowRelation that = (FollowRelation) o;
39-
return Objects.equals(source, that.source) && Objects.equals(target, that.target);
60+
return Objects.equals(source, that.source)
61+
&& Objects.equals(target, that.target)
62+
&& Objects.equals(activityCopyLimit, that.activityCopyLimit);
4063
}
4164

4265
@Override
4366
public int hashCode() {
44-
return Objects.hash(source, target);
67+
return Objects.hash(source, target, activityCopyLimit);
4568
}
4669

4770
@Override
4871
public String toString() {
4972
return MoreObjects.toStringHelper(this)
5073
.add("source", this.source)
5174
.add("target", this.target)
75+
.add("activityCopyLimit", this.activityCopyLimit)
5276
.toString();
5377
}
5478
}

src/test/java/io/getstream/client/BatchClientTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public void followMany() throws Exception {
4444
client.followMany(follows.toArray(new FollowRelation[0])).join();
4545
}
4646

47+
@Test
48+
public void followManyWithPerRelationActivityCopyLimit() throws Exception {
49+
BatchClient client = Client.builder(apiKey, secret).build().batch();
50+
// Test per-relationship activity_copy_limit
51+
client
52+
.followMany(
53+
new FollowRelation[] {
54+
new FollowRelation("flat:1", "flat:2", 10),
55+
new FollowRelation("aggregated:1", "flat:1", 20)
56+
})
57+
.join();
58+
}
59+
4760
@Test
4861
public void unfollowMany() throws Exception {
4962
BatchClient client = Client.builder(apiKey, secret).build().batch();

0 commit comments

Comments
 (0)