Skip to content

Commit f2d064b

Browse files
author
Max Klyga
committed
Add option control whether to keep history for unfollow many operation
1 parent 388c70d commit f2d064b

5 files changed

Lines changed: 111 additions & 14 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'io.getstream.client'
13-
version = '3.1.7'
13+
version = '3.1.8'
1414

1515
dependencies {
1616
sourceCompatibility = 1.8

src/main/java/io/getstream/client/BatchClient.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import io.getstream.core.StreamBatch;
55
import io.getstream.core.exceptions.StreamException;
66
import io.getstream.core.http.Token;
7-
import io.getstream.core.models.Activity;
8-
import io.getstream.core.models.FeedID;
9-
import io.getstream.core.models.FollowRelation;
10-
import io.getstream.core.models.ForeignIDTimePair;
7+
import io.getstream.core.models.*;
8+
import io.getstream.core.KeepHistory;
119
import io.getstream.core.utils.DefaultOptions;
10+
import java8.util.J8Arrays;
1211
import java8.util.concurrent.CompletableFuture;
1312

1413
import java.util.List;
@@ -48,7 +47,23 @@ public CompletableFuture<Void> followMany(Iterable<FollowRelation> follows) thro
4847

4948
public CompletableFuture<Void> unfollowMany(FollowRelation... follows) throws StreamException {
5049
final Token token = buildFollowToken(secret, TokenAction.WRITE);
51-
return batch.unfollowMany(token, follows);
50+
final UnfollowOperation[] ops = J8Arrays.stream(follows)
51+
.map(follow -> new UnfollowOperation(follow, io.getstream.core.KeepHistory.YES))
52+
.toArray(UnfollowOperation[]::new);
53+
return batch.unfollowMany(token, ops);
54+
}
55+
56+
public CompletableFuture<Void> unfollowMany(KeepHistory keepHistory, FollowRelation... follows) throws StreamException {
57+
final Token token = buildFollowToken(secret, TokenAction.WRITE);
58+
final UnfollowOperation[] ops = J8Arrays.stream(follows)
59+
.map(follow -> new UnfollowOperation(follow, keepHistory))
60+
.toArray(UnfollowOperation[]::new);
61+
return batch.unfollowMany(token, ops);
62+
}
63+
64+
public CompletableFuture<Void> unfollowMany(UnfollowOperation... unfollows) throws StreamException {
65+
final Token token = buildFollowToken(secret, TokenAction.WRITE);
66+
return batch.unfollowMany(token, unfollows);
5267
}
5368

5469
public CompletableFuture<List<Activity>> getActivitiesByID(Iterable<String> activityIDs) throws StreamException {

src/main/java/io/getstream/core/StreamBatch.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import io.getstream.core.exceptions.StreamException;
66
import io.getstream.core.http.HTTPClient;
77
import io.getstream.core.http.Token;
8-
import io.getstream.core.models.Activity;
9-
import io.getstream.core.models.FeedID;
10-
import io.getstream.core.models.FollowRelation;
11-
import io.getstream.core.models.ForeignIDTimePair;
8+
import io.getstream.core.models.*;
129
import io.getstream.core.options.CustomQueryParameter;
1310
import io.getstream.core.options.RequestOption;
1411
import java8.util.J8Arrays;
@@ -89,12 +86,12 @@ public CompletableFuture<Void> followMany(Token token, int activityCopyLimit, Fo
8986
}
9087
}
9188

92-
public CompletableFuture<Void> unfollowMany(Token token, FollowRelation... follows) throws StreamException {
93-
checkNotNull(follows, "No feeds to unfollow");
94-
checkArgument(follows.length > 0, "No feeds to unfollow");
89+
public CompletableFuture<Void> unfollowMany(Token token, UnfollowOperation... unfollows) throws StreamException {
90+
checkNotNull(unfollows, "No feeds to unfollow");
91+
checkArgument(unfollows.length > 0, "No feeds to unfollow");
9592

9693
try {
97-
final byte[] payload = toJSON(follows);
94+
final byte[] payload = toJSON(unfollows);
9895
final URL url = buildUnfollowManyURL(baseURL);
9996
return httpClient.execute(buildPost(url, key, token, payload))
10097
.thenApply(response -> {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package io.getstream.core.models;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.google.common.base.MoreObjects;
7+
import io.getstream.core.KeepHistory;
8+
9+
import java.util.Objects;
10+
11+
import static com.google.common.base.Preconditions.checkNotNull;
12+
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
public final class UnfollowOperation {
15+
private final String source;
16+
private final String target;
17+
private final KeepHistory keepHistory;
18+
19+
@JsonCreator
20+
public UnfollowOperation(@JsonProperty("feed_id") String source, @JsonProperty("target_id") String target, @JsonProperty("keep_history") KeepHistory keepHistory) {
21+
checkNotNull(source, "UnfollowOperation 'source' field required");
22+
checkNotNull(target, "UnfollowOperation 'target' field required");
23+
checkNotNull(keepHistory, "UnfollowOperation 'keep history' field required");
24+
25+
this.source = source;
26+
this.target = target;
27+
this.keepHistory = keepHistory;
28+
}
29+
30+
public UnfollowOperation(FollowRelation follow, KeepHistory keepHistory) {
31+
checkNotNull(follow, "UnfollowOperation 'follow' field required");
32+
checkNotNull(keepHistory, "UnfollowOperation 'keep history' field required");
33+
34+
this.source = follow.getSource();
35+
this.target = follow.getTarget();
36+
this.keepHistory = keepHistory;
37+
}
38+
39+
public String getSource() {
40+
return this.source;
41+
}
42+
43+
public String getTarget() {
44+
return this.target;
45+
}
46+
47+
public KeepHistory getKeepHistory() {
48+
return this.keepHistory;
49+
}
50+
51+
@Override
52+
public boolean equals(Object o) {
53+
if (this == o) return true;
54+
if (o == null || getClass() != o.getClass()) return false;
55+
UnfollowOperation that = (UnfollowOperation) o;
56+
return Objects.equals(source, that.source) &&
57+
Objects.equals(target, that.target) &&
58+
Objects.equals(keepHistory, that.keepHistory);
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return Objects.hash(source, target, keepHistory);
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return MoreObjects.toStringHelper(this)
69+
.add("source", this.source)
70+
.add("target", this.target)
71+
.add("keep_history", this.keepHistory)
72+
.toString();
73+
}
74+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.getstream.client;
22

33
import com.google.common.collect.ImmutableMap;
4+
import io.getstream.core.KeepHistory;
45
import io.getstream.core.models.*;
56
import org.junit.Test;
67

@@ -45,6 +46,16 @@ public void unfollowMany() throws Exception {
4546
new FollowRelation("flat:1", "flat:2"),
4647
new FollowRelation("aggregated:1", "flat:1")
4748
}).join();
49+
50+
client.unfollowMany(KeepHistory.NO, new FollowRelation[]{
51+
new FollowRelation("flat:1", "flat:2"),
52+
new FollowRelation("aggregated:1", "flat:1")
53+
}).join();
54+
55+
client.unfollowMany(new UnfollowOperation[]{
56+
new UnfollowOperation("flat:1", "flat:2", KeepHistory.NO),
57+
new UnfollowOperation("aggregated:1", "flat:1", KeepHistory.YES)
58+
}).join();
4859
}
4960

5061
@Test

0 commit comments

Comments
 (0)