Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/main/java/io/getstream/core/models/FollowRelation.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.getstream.core.models;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import java.util.Objects;
Expand All @@ -12,15 +14,28 @@
public final class FollowRelation {
private final String source;
private final String target;
private final Integer activityCopyLimit;

@JsonCreator
public FollowRelation(
@JsonProperty("feed_id") String source, @JsonProperty("target_id") String target) {
@JsonProperty("feed_id") String source,
@JsonProperty("target_id") String target,
@JsonProperty("activity_copy_limit") Integer activityCopyLimit) {
checkNotNull(source, "FollowRelation 'source' field required");
checkNotNull(target, "FollowRelation 'target' field required");
if (activityCopyLimit != null) {
checkArgument(activityCopyLimit >= 0, "Activity copy limit must be non negative");
}

this.source = source;
this.target = target;
this.activityCopyLimit = activityCopyLimit;
}

public FollowRelation(
@JsonProperty("feed_id") String source,
@JsonProperty("target_id") String target) {
this(source, target, null);
}

public String getSource() {
Expand All @@ -31,24 +46,33 @@ public String getTarget() {
return this.target;
}

@JsonProperty("activity_copy_limit")
@JsonInclude(JsonInclude.Include.NON_NULL)
public Integer getActivityCopyLimit() {
return this.activityCopyLimit;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FollowRelation that = (FollowRelation) o;
return Objects.equals(source, that.source) && Objects.equals(target, that.target);
return Objects.equals(source, that.source)
&& Objects.equals(target, that.target)
&& Objects.equals(activityCopyLimit, that.activityCopyLimit);
}

@Override
public int hashCode() {
return Objects.hash(source, target);
return Objects.hash(source, target, activityCopyLimit);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("source", this.source)
.add("target", this.target)
.add("activityCopyLimit", this.activityCopyLimit)
.toString();
}
}
13 changes: 13 additions & 0 deletions src/test/java/io/getstream/client/BatchClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public void followMany() throws Exception {
client.followMany(follows.toArray(new FollowRelation[0])).join();
}

@Test
public void followManyWithPerRelationActivityCopyLimit() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
// Test per-relationship activity_copy_limit
client
.followMany(
new FollowRelation[] {
new FollowRelation("flat:1", "flat:2", 10),
new FollowRelation("aggregated:1", "flat:1", 20)
})
.join();
}

@Test
public void unfollowMany() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
Expand Down
Loading