Skip to content

Commit c58917e

Browse files
authored
Merge pull request #134 from GetStream/soft-delete
[PBE-1134] Added soft delete reactions support
2 parents 346f408 + f0c847a commit c58917e

File tree

7 files changed

+82
-6
lines changed

7 files changed

+82
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
## 📝 About Stream
2222

23-
You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
23+
You can sign up for a Stream account at our [Get Started](https://getstream.io/activity-feeds/docs/java/?language=java) page.
2424

2525
You can use this library to access feeds API endpoints server-side.
2626

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ public CompletableFuture<Void> update(Reaction reaction, FeedID... targetFeeds)
194194

195195
public CompletableFuture<Void> delete(String id) throws StreamException {
196196
final Token token = buildReactionsToken(secret, TokenAction.DELETE);
197-
return reactions.delete(token, id);
197+
return reactions.delete(token, id, false);
198+
}
199+
200+
public CompletableFuture<Void> delete(String id, Boolean soft) throws StreamException {
201+
final Token token = buildReactionsToken(secret, TokenAction.DELETE);
202+
return reactions.delete(token, id, soft);
203+
}
204+
205+
public CompletableFuture<Void> softDelete(String id) throws StreamException {
206+
final Token token = buildReactionsToken(secret, TokenAction.DELETE);
207+
return reactions.delete(token, id, true);
208+
}
209+
210+
public CompletableFuture<Void> restore(String id) throws StreamException {
211+
final Token token = buildReactionsToken(secret, TokenAction.WRITE);
212+
return reactions.restore(token, id);
198213
}
199214
}

src/main/java/io/getstream/cloud/CloudReactionsClient.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,19 @@ public CompletableFuture<Void> update(Reaction reaction, FeedID... targetFeeds)
200200
}
201201

202202
public CompletableFuture<Void> delete(String id) throws StreamException {
203-
return reactions.delete(token, id);
203+
return reactions.delete(token, id, false);
204+
}
205+
206+
public CompletableFuture<Void> delete(String id, Boolean soft) throws StreamException {
207+
return reactions.delete(token, id, soft);
208+
}
209+
210+
public CompletableFuture<Void> softDelete(String id) throws StreamException {
211+
return reactions.delete(token, id, true);
212+
}
213+
214+
public CompletableFuture<Void> restore(String id) throws StreamException {
215+
return reactions.restore(token, id);
204216
}
205217

206218
public class Params {

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.common.collect.ImmutableMap;
1313
import io.getstream.core.exceptions.StreamException;
1414
import io.getstream.core.http.HTTPClient;
15+
import io.getstream.core.http.Request;
1516
import io.getstream.core.http.Token;
1617
import io.getstream.core.models.FeedID;
1718
import io.getstream.core.models.Paginated;
@@ -283,14 +284,40 @@ public CompletableFuture<Void> update(Token token, Reaction reaction, FeedID...
283284
}
284285
}
285286

286-
public CompletableFuture<Void> delete(Token token, String id) throws StreamException {
287+
public CompletableFuture<Void> delete(Token token, String id, Boolean soft) throws StreamException {
287288
checkNotNull(id, "Reaction id can't be null");
288289
checkArgument(!id.isEmpty(), "Reaction id can't be empty");
289290

290291
try {
291292
final URL url = buildReactionsURL(baseURL, id + '/');
293+
294+
final Request deleteRequest = soft ? buildDelete(url, key, token, new CustomQueryParameter("soft", "true"))
295+
: buildDelete(url, key, token);
296+
297+
return httpClient
298+
.execute(deleteRequest)
299+
.thenApply(
300+
response -> {
301+
try {
302+
return deserializeError(response);
303+
} catch (StreamException | IOException e) {
304+
throw new CompletionException(e);
305+
}
306+
});
307+
} catch (MalformedURLException | URISyntaxException e) {
308+
throw new StreamException(e);
309+
}
310+
}
311+
312+
public CompletableFuture<Void> restore(Token token, String id) throws StreamException {
313+
checkNotNull(id, "Reaction id can't be null");
314+
checkArgument(!id.isEmpty(), "Reaction id can't be empty");
315+
316+
try {
317+
final URL url = buildReactionsURL(baseURL, id + "/restore/");
318+
byte[] payload = new byte[0];
292319
return httpClient
293-
.execute(buildDelete(url, key, token))
320+
.execute(buildPut(url, key, token, payload))
294321
.thenApply(
295322
response -> {
296323
try {

src/main/java/io/getstream/core/http/Request.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ public Request build() throws MalformedURLException, URISyntaxException {
155155
return new Request(this);
156156
}
157157
}
158-
}
158+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,15 @@ public void delete() throws Exception {
114114
Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join();
115115
client.reactions().delete(reply.getId()).join();
116116
}
117+
118+
@Test
119+
public void softDelete() throws Exception {
120+
Client client = Client.builder(apiKey, secret).build();
121+
122+
Reaction data =
123+
Reaction.builder().activityID("ed2837a6-0a3b-4679-adc1-778a1704852d").kind("like").build();
124+
Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join();
125+
client.reactions().softDelete(reply.getId()).join();
126+
client.reactions().restore(reply.getId()).join();
127+
}
117128
}

src/test/java/io/getstream/cloud/CloudReactionsClientTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,15 @@ public void delete() throws Exception {
9090
Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join();
9191
client.reactions().delete(reply.getId()).join();
9292
}
93+
94+
@Test
95+
public void softDelete() throws Exception {
96+
Client client = Client.builder(apiKey, secret).build();
97+
98+
Reaction data =
99+
Reaction.builder().activityID("ed2837a6-0a3b-4679-adc1-778a1704852d").kind("like").build();
100+
Reaction reply = client.reactions().add("user-id", data, new FeedID("flat", "1")).join();
101+
client.reactions().softDelete(reply.getId()).join();
102+
client.reactions().restore(reply.getId()).join();
103+
}
93104
}

0 commit comments

Comments
 (0)