From a2b2dc15db2c927c9108322c872754a90db22569 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 12:00:11 +0100 Subject: [PATCH 01/11] chore: added soft delete method --- src/main/java/io/getstream/client/ReactionsClient.java | 7 ++++++- src/main/java/io/getstream/core/StreamReactions.java | 4 ++-- src/main/java/io/getstream/core/http/Request.java | 9 +++++++-- src/main/java/io/getstream/core/utils/Request.java | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/getstream/client/ReactionsClient.java b/src/main/java/io/getstream/client/ReactionsClient.java index f7020030..ba24aafa 100644 --- a/src/main/java/io/getstream/client/ReactionsClient.java +++ b/src/main/java/io/getstream/client/ReactionsClient.java @@ -194,6 +194,11 @@ 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 softDelete(String id) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.DELETE); + return reactions.delete(token, id, true); } } diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 1ce80210..8fbf9755 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -283,14 +283,14 @@ 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 + '/'); return httpClient - .execute(buildDelete(url, key, token)) + .execute(buildDelete(url, key, token, soft)) .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..8ad25e20 100644 --- a/src/main/java/io/getstream/core/http/Request.java +++ b/src/main/java/io/getstream/core/http/Request.java @@ -136,9 +136,14 @@ public Builder put(byte[] body) { return this; } - public Builder delete() { + public Builder delete(Boolean soft) { this.method = Method.DELETE; this.body = null; + + if (soft) { + this.addQueryParameter("soft", "true"); + } + return this; } @@ -155,4 +160,4 @@ public Request build() throws MalformedURLException, URISyntaxException { return new Request(this); } } -} +} diff --git a/src/main/java/io/getstream/core/utils/Request.java b/src/main/java/io/getstream/core/utils/Request.java index 05a2f65b..58e1d277 100644 --- a/src/main/java/io/getstream/core/utils/Request.java +++ b/src/main/java/io/getstream/core/utils/Request.java @@ -31,9 +31,9 @@ public static io.getstream.core.http.Request buildGet( } public static io.getstream.core.http.Request buildDelete( - URL url, String apiKey, Token token, RequestOption... options) + URL url, String apiKey, Token token, Boolean soft, RequestOption... options) throws URISyntaxException, MalformedURLException { - return buildRequest(url, apiKey, token, options).delete().build(); + return buildRequest(url, apiKey, token, options).delete(soft).build(); } public static io.getstream.core.http.Request buildPost( From d57451d636b5a39a4ab3fb1697360ba2682d07db Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 12:39:08 +0100 Subject: [PATCH 02/11] chore: added restore method --- .../io/getstream/client/ReactionsClient.java | 10 +++++++++ .../io/getstream/core/StreamReactions.java | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/io/getstream/client/ReactionsClient.java b/src/main/java/io/getstream/client/ReactionsClient.java index ba24aafa..074244ac 100644 --- a/src/main/java/io/getstream/client/ReactionsClient.java +++ b/src/main/java/io/getstream/client/ReactionsClient.java @@ -197,8 +197,18 @@ public CompletableFuture delete(String id) throws StreamException { 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/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 8fbf9755..cfc522b8 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -303,4 +303,25 @@ public CompletableFuture delete(Token token, String id, Boolean soft) thro 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/"); + return httpClient + .execute(buildPut(url, key, token, null)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); + } + } } From c12a36f89b7c8e96b0f90451b8c143362e6bb011 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 14:33:57 +0100 Subject: [PATCH 03/11] chore: added methods to cloudreactionsclient --- .../io/getstream/cloud/CloudReactionsClient.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/getstream/cloud/CloudReactionsClient.java b/src/main/java/io/getstream/cloud/CloudReactionsClient.java index f4b9b2b5..442b518d 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, Boolean soft) throws StreamException { + return reactions.restore(token, id); } public class Params { From d3cc927a62482f15a3b2643453277ee3b25c39dc Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 14:51:27 +0100 Subject: [PATCH 04/11] chore: fix error --- .../io/getstream/core/StreamReactions.java | 18 ++++++++++++++++-- .../java/io/getstream/core/http/Request.java | 7 +------ .../java/io/getstream/core/utils/Request.java | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index cfc522b8..0fee8ae8 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -289,8 +289,20 @@ public CompletableFuture delete(Token token, String id, Boolean soft) thro try { final URL url = buildReactionsURL(baseURL, id + '/'); - return httpClient - .execute(buildDelete(url, key, token, soft)) + if (soft) { + return httpClient + .execute(buildDelete(url, key, token, new CustomQueryParameter("soft", "true"))) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } else { + return httpClient + .execute(buildDelete(url, key, token)) .thenApply( response -> { try { @@ -299,6 +311,8 @@ public CompletableFuture delete(Token token, String id, Boolean soft) thro throw new CompletionException(e); } }); + } + } catch (MalformedURLException | URISyntaxException e) { throw new StreamException(e); } diff --git a/src/main/java/io/getstream/core/http/Request.java b/src/main/java/io/getstream/core/http/Request.java index 8ad25e20..7b58d618 100644 --- a/src/main/java/io/getstream/core/http/Request.java +++ b/src/main/java/io/getstream/core/http/Request.java @@ -136,14 +136,9 @@ public Builder put(byte[] body) { return this; } - public Builder delete(Boolean soft) { + public Builder delete() { this.method = Method.DELETE; this.body = null; - - if (soft) { - this.addQueryParameter("soft", "true"); - } - return this; } diff --git a/src/main/java/io/getstream/core/utils/Request.java b/src/main/java/io/getstream/core/utils/Request.java index 58e1d277..05a2f65b 100644 --- a/src/main/java/io/getstream/core/utils/Request.java +++ b/src/main/java/io/getstream/core/utils/Request.java @@ -31,9 +31,9 @@ public static io.getstream.core.http.Request buildGet( } public static io.getstream.core.http.Request buildDelete( - URL url, String apiKey, Token token, Boolean soft, RequestOption... options) + URL url, String apiKey, Token token, RequestOption... options) throws URISyntaxException, MalformedURLException { - return buildRequest(url, apiKey, token, options).delete(soft).build(); + return buildRequest(url, apiKey, token, options).delete().build(); } public static io.getstream.core.http.Request buildPost( From 685d2695a98ed4cbff39f4159c157ee69e3ab585 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 14:53:15 +0100 Subject: [PATCH 05/11] chore: removed extra parameter --- src/main/java/io/getstream/cloud/CloudReactionsClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/getstream/cloud/CloudReactionsClient.java b/src/main/java/io/getstream/cloud/CloudReactionsClient.java index 442b518d..c1084f1a 100644 --- a/src/main/java/io/getstream/cloud/CloudReactionsClient.java +++ b/src/main/java/io/getstream/cloud/CloudReactionsClient.java @@ -211,7 +211,7 @@ public CompletableFuture softDelete(String id) throws StreamException { return reactions.delete(token, id, true); } - public CompletableFuture restore(String id, Boolean soft) throws StreamException { + public CompletableFuture restore(String id) throws StreamException { return reactions.restore(token, id); } From 3de8808ffe8ae40f4bcc340f32d1f0b551410a70 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 15:01:57 +0100 Subject: [PATCH 06/11] chore: refactor --- .../io/getstream/core/StreamReactions.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 0fee8ae8..d5cd2e49 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; @@ -289,30 +290,20 @@ public CompletableFuture delete(Token token, String id, Boolean soft) thro try { final URL url = buildReactionsURL(baseURL, id + '/'); - if (soft) { - return httpClient - .execute(buildDelete(url, key, token, new CustomQueryParameter("soft", "true"))) - .thenApply( - response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } else { - return httpClient - .execute(buildDelete(url, key, token)) - .thenApply( - response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + final Request deleteRequest = soft ? buildDelete(url, key, token, new CustomQueryParameter("soft", "true")) + : buildDelete(url, key, token, new CustomQueryParameter("soft", "true")); + + 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); } From 07698623939ee83ea06bea49b4cc11fcbb7115ad Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 15:20:36 +0100 Subject: [PATCH 07/11] chore: added softDelete / restore test --- .../io/getstream/client/ReactionsClientTest.java | 12 ++++++++++++ .../io/getstream/cloud/CloudReactionsClientTest.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/test/java/io/getstream/client/ReactionsClientTest.java b/src/test/java/io/getstream/client/ReactionsClientTest.java index 23d502d8..3fd7845c 100644 --- a/src/test/java/io/getstream/client/ReactionsClientTest.java +++ b/src/test/java/io/getstream/client/ReactionsClientTest.java @@ -115,3 +115,15 @@ public void delete() throws Exception { 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..800c9aa1 100644 --- a/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java +++ b/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java @@ -91,3 +91,15 @@ public void delete() throws Exception { 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(); + } +} From 511db5f9b93dff2134e687924d1cf0b9cd591ac6 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 15:23:55 +0100 Subject: [PATCH 08/11] chore: fix error --- src/test/java/io/getstream/client/ReactionsClientTest.java | 3 +-- src/test/java/io/getstream/cloud/CloudReactionsClientTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/getstream/client/ReactionsClientTest.java b/src/test/java/io/getstream/client/ReactionsClientTest.java index 3fd7845c..efcc4aa8 100644 --- a/src/test/java/io/getstream/client/ReactionsClientTest.java +++ b/src/test/java/io/getstream/client/ReactionsClientTest.java @@ -114,9 +114,8 @@ 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 + @Test public void softDelete() throws Exception { Client client = Client.builder(apiKey, secret).build(); diff --git a/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java b/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java index 800c9aa1..998c5527 100644 --- a/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java +++ b/src/test/java/io/getstream/cloud/CloudReactionsClientTest.java @@ -90,9 +90,8 @@ 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 + @Test public void softDelete() throws Exception { Client client = Client.builder(apiKey, secret).build(); From 92dd2dd3ff2b9defd8efde41fafca022a8474a91 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 15:44:44 +0100 Subject: [PATCH 09/11] chore: fix null --- src/main/java/io/getstream/core/StreamReactions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index d5cd2e49..223cec3b 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -315,8 +315,9 @@ public CompletableFuture restore(Token token, String id) throws StreamExce try { final URL url = buildReactionsURL(baseURL, id + "/restore/"); + byte[] payload = new byte[0]; return httpClient - .execute(buildPut(url, key, token, null)) + .execute(buildPut(url, key, token, payload)) .thenApply( response -> { try { From dc18ec3c7ebd6275d75fca67aa5fc2b2666ea02d Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 15:50:46 +0100 Subject: [PATCH 10/11] chore: updated link in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From f0c847aad8d700f2d6cb811400c5fda5d15e67f1 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 23 Oct 2023 16:38:50 +0100 Subject: [PATCH 11/11] chore: fixed copy error --- src/main/java/io/getstream/core/StreamReactions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 223cec3b..b9772533 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -292,7 +292,7 @@ public CompletableFuture delete(Token token, String id, Boolean soft) thro final URL url = buildReactionsURL(baseURL, id + '/'); final Request deleteRequest = soft ? buildDelete(url, key, token, new CustomQueryParameter("soft", "true")) - : buildDelete(url, key, token, new CustomQueryParameter("soft", "true")); + : buildDelete(url, key, token); return httpClient .execute(deleteRequest)