diff --git a/README.md b/README.md index e423c2a2..38878108 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ ## 📝 About Stream -You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page. +You can sign up for a Stream account at our [Get Started](https://getstream.io/activity-feeds/docs/java/?language=java) page. You can use this library to access feeds API endpoints server-side. diff --git a/src/main/java/io/getstream/client/ReactionsClient.java b/src/main/java/io/getstream/client/ReactionsClient.java index f7020030..074244ac 100644 --- a/src/main/java/io/getstream/client/ReactionsClient.java +++ b/src/main/java/io/getstream/client/ReactionsClient.java @@ -194,6 +194,21 @@ public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) public CompletableFuture delete(String id) throws StreamException { final Token token = buildReactionsToken(secret, TokenAction.DELETE); - return reactions.delete(token, id); + return reactions.delete(token, id, false); + } + + public CompletableFuture delete(String id, Boolean soft) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.DELETE); + return reactions.delete(token, id, soft); + } + + public CompletableFuture softDelete(String id) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.DELETE); + return reactions.delete(token, id, true); + } + + public CompletableFuture restore(String id) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.WRITE); + return reactions.restore(token, id); } } diff --git a/src/main/java/io/getstream/cloud/CloudReactionsClient.java b/src/main/java/io/getstream/cloud/CloudReactionsClient.java index f4b9b2b5..c1084f1a 100644 --- a/src/main/java/io/getstream/cloud/CloudReactionsClient.java +++ b/src/main/java/io/getstream/cloud/CloudReactionsClient.java @@ -200,7 +200,19 @@ public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) } public CompletableFuture delete(String id) throws StreamException { - return reactions.delete(token, id); + return reactions.delete(token, id, false); + } + + public CompletableFuture delete(String id, Boolean soft) throws StreamException { + return reactions.delete(token, id, soft); + } + + public CompletableFuture softDelete(String id) throws StreamException { + return reactions.delete(token, id, true); + } + + public CompletableFuture restore(String id) throws StreamException { + return reactions.restore(token, id); } public class Params { diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 1ce80210..b9772533 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableMap; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.HTTPClient; +import io.getstream.core.http.Request; import io.getstream.core.http.Token; import io.getstream.core.models.FeedID; import io.getstream.core.models.Paginated; @@ -283,14 +284,40 @@ public CompletableFuture update(Token token, Reaction reaction, FeedID... } } - public CompletableFuture delete(Token token, String id) throws StreamException { + public CompletableFuture delete(Token token, String id, Boolean soft) throws StreamException { checkNotNull(id, "Reaction id can't be null"); checkArgument(!id.isEmpty(), "Reaction id can't be empty"); try { final URL url = buildReactionsURL(baseURL, id + '/'); + + final Request deleteRequest = soft ? buildDelete(url, key, token, new CustomQueryParameter("soft", "true")) + : buildDelete(url, key, token); + + return httpClient + .execute(deleteRequest) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); + } + } + + public CompletableFuture restore(Token token, String id) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); + + try { + final URL url = buildReactionsURL(baseURL, id + "/restore/"); + byte[] payload = new byte[0]; return httpClient - .execute(buildDelete(url, key, token)) + .execute(buildPut(url, key, token, payload)) .thenApply( response -> { try { diff --git a/src/main/java/io/getstream/core/http/Request.java b/src/main/java/io/getstream/core/http/Request.java index b5b6d40d..7b58d618 100644 --- a/src/main/java/io/getstream/core/http/Request.java +++ b/src/main/java/io/getstream/core/http/Request.java @@ -155,4 +155,4 @@ public Request build() throws MalformedURLException, URISyntaxException { return new Request(this); } } -} +} diff --git a/src/test/java/io/getstream/client/ReactionsClientTest.java b/src/test/java/io/getstream/client/ReactionsClientTest.java index 23d502d8..efcc4aa8 100644 --- a/src/test/java/io/getstream/client/ReactionsClientTest.java +++ b/src/test/java/io/getstream/client/ReactionsClientTest.java @@ -114,4 +114,15 @@ public void delete() throws Exception { Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join(); client.reactions().delete(reply.getId()).join(); } + + @Test + public void softDelete() throws Exception { + Client client = Client.builder(apiKey, secret).build(); + + Reaction data = + Reaction.builder().activityID("ed2837a6-0a3b-4679-adc1-778a1704852d").kind("like").build(); + Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join(); + client.reactions().softDelete(reply.getId()).join(); + client.reactions().restore(reply.getId()).join(); + } } diff --git a/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java b/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java index 5c71282e..998c5527 100644 --- a/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java +++ b/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java @@ -90,4 +90,15 @@ public void delete() throws Exception { Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join(); client.reactions().delete(reply.getId()).join(); } + + @Test + public void softDelete() throws Exception { + Client client = Client.builder(apiKey, secret).build(); + + Reaction data = + Reaction.builder().activityID("ed2837a6-0a3b-4679-adc1-778a1704852d").kind("like").build(); + Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join(); + client.reactions().softDelete(reply.getId()).join(); + client.reactions().restore(reply.getId()).join(); + } }