From 818ee944bcb23eeb5fec27113ef8289316c0a392 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Fri, 3 Oct 2025 13:27:18 +0200 Subject: [PATCH 1/3] chore: discard_actors --- .../java/io/getstream/client/FlatFeed.java | 23 +++++++ .../getstream/core/options/DiscardActors.java | 41 +++++++++++++ .../io/getstream/client/FlatFeedTest.java | 60 ++++++++++++++++++- 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/getstream/core/options/DiscardActors.java diff --git a/src/main/java/io/getstream/client/FlatFeed.java b/src/main/java/io/getstream/client/FlatFeed.java index f10e8824..0891e3f2 100644 --- a/src/main/java/io/getstream/client/FlatFeed.java +++ b/src/main/java/io/getstream/client/FlatFeed.java @@ -127,6 +127,29 @@ limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking), rank }); } + public CompletableFuture> getActivities(RequestOption... options) + throws StreamException { + // If no options provided, use defaults + if (options == null || options.length == 0) { + options = new RequestOption[] { + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER + }; + } + + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } public CompletableFuture> getCustomActivities(Class type) throws StreamException { return getCustomActivities( diff --git a/src/main/java/io/getstream/core/options/DiscardActors.java b/src/main/java/io/getstream/core/options/DiscardActors.java new file mode 100644 index 00000000..e14ba56b --- /dev/null +++ b/src/main/java/io/getstream/core/options/DiscardActors.java @@ -0,0 +1,41 @@ +package io.getstream.core.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.getstream.core.http.Request; +import java.util.List; + +public final class DiscardActors implements RequestOption { + private final String actors; + private final String separator; + + public DiscardActors(String... actors) { + this(actors, ","); + } + + public DiscardActors(List actors) { + this(actors, ","); + } + + public DiscardActors(String[] actors, String separator) { + checkNotNull(actors, "Actors list cannot be null"); + this.actors = String.join(separator != null ? separator : ",", actors); + this.separator = separator; + } + + public DiscardActors(List actors, String separator) { + checkNotNull(actors, "Actors list cannot be null"); + this.actors = String.join(separator != null ? separator : ",", actors); + this.separator = separator; + } + + @Override + public void apply(Request.Builder builder) { + if (actors != null && !actors.isEmpty()) { + builder.addQueryParameter("discard_actors", actors); + if (separator != null && !separator.equals(",")) { + builder.addQueryParameter("discard_actors_sep", separator); + } + } + } +} diff --git a/src/test/java/io/getstream/client/FlatFeedTest.java b/src/test/java/io/getstream/client/FlatFeedTest.java index 2ee282c9..1afc7097 100644 --- a/src/test/java/io/getstream/client/FlatFeedTest.java +++ b/src/test/java/io/getstream/client/FlatFeedTest.java @@ -7,7 +7,11 @@ import io.getstream.core.models.Activity; import io.getstream.core.models.Data; import io.getstream.core.models.EnrichedActivity; +import io.getstream.core.options.DiscardActors; import io.getstream.core.options.EnrichmentFlags; +import io.getstream.core.options.Filter; +import io.getstream.core.options.Limit; +import io.getstream.core.options.Offset; import java.util.Collections; import java.util.List; import java8.util.concurrent.CompletionException; @@ -101,6 +105,60 @@ public void invalidFeedType() throws Exception { .build(); FlatFeed feed = client.flatFeed("aggregated", "1"); - List result = feed.getActivities().join(); + feed.getActivities().join(); + } + + + @Test + public void testDiscardActorsOptions() { + // Test DiscardActors with array + DiscardActors discardActors1 = new DiscardActors("user1", "user2", "user3"); + + // Test DiscardActors with List + List actors = java.util.Arrays.asList("user4", "user5"); + DiscardActors discardActors2 = new DiscardActors(actors); + + // Test DiscardActors with custom separator + DiscardActors discardActors3 = new DiscardActors(new String[]{"user6", "user7"}, ";"); + + // Test DiscardActors with List and custom separator + DiscardActors discardActors4 = new DiscardActors(actors, "|"); + + // Basic validation that objects were created + assert discardActors1 != null; + assert discardActors2 != null; + assert discardActors3 != null; + assert discardActors4 != null; + } + + @Test + public void testGetActivitiesWithRequestOptions() throws Exception { + Client client = + Client.builder(apiKey, secret) + .httpClient(new OKHTTPClientAdapter(new OkHttpClient())) + .build(); + + FlatFeed feed = client.flatFeed("flat", "test-request-options"); + + // Test with just DiscardActors + DiscardActors discardActors = new DiscardActors("actor1", "actor2", "actor3"); + List result1 = feed.getActivities(discardActors).join(); + assert result1 != null; + + // Test with DiscardActors + Limit + Filter + List actors = java.util.Arrays.asList("actor4", "actor5"); + DiscardActors discardActors2 = new DiscardActors(actors); + Filter filter = new Filter().refresh(); + List result2 = feed.getActivities(new Limit(10), filter, discardActors2).join(); + assert result2 != null; + + // Test with all parameters + List result3 = feed.getActivities( + new Limit(20), + new Offset(5), + new Filter().refresh(), + new DiscardActors("actor6", "actor7") + ).join(); + assert result3 != null; } } From 36e8171ec3a5432ddabe8f467750f7c1d59d5f38 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Fri, 3 Oct 2025 14:14:33 +0200 Subject: [PATCH 2/3] chore: update test docs --- src/test/java/io/getstream/client/ModerationClientTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/getstream/client/ModerationClientTest.java b/src/test/java/io/getstream/client/ModerationClientTest.java index 4f6f19a5..d1022fbf 100644 --- a/src/test/java/io/getstream/client/ModerationClientTest.java +++ b/src/test/java/io/getstream/client/ModerationClientTest.java @@ -99,7 +99,8 @@ public void testActivityModerated() throws Exception { assertNotNull(activityResponse); ModerationResponse m = activityResponse.getModerationResponse(); assertEquals(m.getStatus(), "complete"); - assertEquals(m.getRecommendedAction(), "remove"); + assertEquals(m.getRecommendedAction(), "remove");//if this fails,most likely blocklist is missing + //https://getstream.slack.com/archives/C02PXEZ6MCN/p1759493441067379 } @Test From 5fe380b9d38518863711f9f8bd0b919298396360 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Fri, 3 Oct 2025 14:25:30 +0200 Subject: [PATCH 3/3] chore: add discard url mock --- .../io/getstream/client/FlatFeedTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/test/java/io/getstream/client/FlatFeedTest.java b/src/test/java/io/getstream/client/FlatFeedTest.java index 1afc7097..b007d4cb 100644 --- a/src/test/java/io/getstream/client/FlatFeedTest.java +++ b/src/test/java/io/getstream/client/FlatFeedTest.java @@ -17,6 +17,7 @@ import java8.util.concurrent.CompletionException; import okhttp3.OkHttpClient; import org.junit.Test; +import java.util.concurrent.atomic.AtomicReference; public class FlatFeedTest { private static final String apiKey = @@ -161,4 +162,62 @@ public void testGetActivitiesWithRequestOptions() throws Exception { ).join(); assert result3 != null; } + + @Test + public void testGetActivitiesUrlParameters() throws Exception { + // Create a mock HTTP client that captures the request URL + AtomicReference capturedUrl = new AtomicReference<>(); + + // Create a custom OkHttpClient that intercepts requests + OkHttpClient mockClient = new OkHttpClient.Builder() + .addInterceptor(chain -> { + capturedUrl.set(chain.request().url().toString()); + // Return a mock response + return new okhttp3.Response.Builder() + .request(chain.request()) + .protocol(okhttp3.Protocol.HTTP_1_1) + .code(200) + .message("OK") + .body(okhttp3.ResponseBody.create( + okhttp3.MediaType.parse("application/json"), + "{\"results\":[],\"next\":\"\",\"duration\":\"0ms\"}" + )) + .build(); + }) + .build(); + + Client client = Client.builder("test-key", "test-secret") + .httpClient(new OKHTTPClientAdapter(mockClient)) + .build(); + + FlatFeed feed = client.flatFeed("flat", "test-url-params"); + + // Test with multiple RequestOptions + feed.getActivities( + new Limit(20), + new Offset(5), + new Filter().refresh(), + new DiscardActors("actor1", "actor2", "actor3") + ).join(); + + String url = capturedUrl.get(); + assert url != null; + + // Verify URL contains expected parameters + assert url.contains("limit=20") : "URL should contain limit=20, got: " + url; + assert url.contains("offset=5") : "URL should contain offset=5, got: " + url; + assert url.contains("refresh=1") : "URL should contain refresh=1, got: " + url; + assert url.contains("discard_actors=actor1,actor2,actor3") : "URL should contain discard_actors, got: " + url; + + // Test with custom separator + capturedUrl.set(null); + feed.getActivities( + new DiscardActors(new String[]{"actor4", "actor5"}, "|") + ).join(); + + url = capturedUrl.get(); + assert url != null; + assert url.contains("discard_actors=actor4%7Cactor5") : "URL should contain pipe-separated actors, got: " + url; + assert url.contains("discard_actors_sep=%7C") : "URL should contain discard_actors_sep, got: " + url; + } }