Skip to content

Commit e4960fc

Browse files
authored
Merge pull request #187 from GetStream/discard
[FEEDS-1110] add discard actor support in enriched activities
2 parents 33ec6da + 456bcd0 commit e4960fc

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,31 @@ CompletableFuture<? extends List<? extends Group<EnrichedActivity>>> getEnriched
450450
});
451451
}
452452

453+
public CompletableFuture<? extends List<? extends Group<EnrichedActivity>>> getEnrichedActivities(
454+
RequestOption... options) throws StreamException {
455+
// If no options provided, use defaults
456+
if (options == null || options.length == 0) {
457+
options = new RequestOption[] {
458+
DefaultOptions.DEFAULT_LIMIT,
459+
DefaultOptions.DEFAULT_OFFSET,
460+
DefaultOptions.DEFAULT_FILTER,
461+
DefaultOptions.DEFAULT_ENRICHMENT_FLAGS,
462+
DefaultOptions.DEFAULT_MARKER
463+
};
464+
}
465+
466+
return getClient()
467+
.getEnrichedActivities(getID(), options)
468+
.thenApply(
469+
response -> {
470+
try {
471+
return deserializeContainer(response, Group.class, EnrichedActivity.class);
472+
} catch (StreamException | IOException e) {
473+
throw new CompletionException(e);
474+
}
475+
});
476+
}
477+
453478
public <T> CompletableFuture<? extends List<? extends Group<T>>> getEnrichedCustomActivities(
454479
Class<T> type) throws StreamException {
455480
return getEnrichedCustomActivities(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,31 @@ limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking
463463
});
464464
}
465465

466+
public CompletableFuture<List<EnrichedActivity>> getEnrichedActivities(RequestOption... options)
467+
throws StreamException {
468+
// If no options provided, use defaults
469+
if (options == null || options.length == 0) {
470+
options = new RequestOption[] {
471+
DefaultOptions.DEFAULT_LIMIT,
472+
DefaultOptions.DEFAULT_OFFSET,
473+
DefaultOptions.DEFAULT_FILTER,
474+
DefaultOptions.DEFAULT_ENRICHMENT_FLAGS,
475+
DefaultOptions.DEFAULT_MARKER
476+
};
477+
}
478+
479+
return getClient()
480+
.getEnrichedActivities(getID(), options)
481+
.thenApply(
482+
response -> {
483+
try {
484+
return deserializeContainer(response, EnrichedActivity.class);
485+
} catch (StreamException | IOException e) {
486+
throw new CompletionException(e);
487+
}
488+
});
489+
}
490+
466491
public <T> CompletableFuture<List<T>> getEnrichedCustomActivities(Class<T> type)
467492
throws StreamException {
468493
return getEnrichedCustomActivities(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,31 @@ limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking
421421
});
422422
}
423423

424+
public CompletableFuture<List<EnrichedActivity>> getEnrichedActivities(RequestOption... options)
425+
throws StreamException {
426+
// If no options provided, use defaults
427+
if (options == null || options.length == 0) {
428+
options = new RequestOption[] {
429+
DefaultOptions.DEFAULT_LIMIT,
430+
DefaultOptions.DEFAULT_OFFSET,
431+
DefaultOptions.DEFAULT_FILTER,
432+
DefaultOptions.DEFAULT_ENRICHMENT_FLAGS,
433+
DefaultOptions.DEFAULT_MARKER
434+
};
435+
}
436+
437+
return getClient()
438+
.getEnrichedActivities(getID(), options)
439+
.thenApply(
440+
(Response response) -> {
441+
try {
442+
return deserializeContainer(response, EnrichedActivity.class);
443+
} catch (StreamException | IOException e) {
444+
throw new CompletionException(e);
445+
}
446+
});
447+
}
448+
424449
public <T> CompletableFuture<List<T>> getEnrichedCustomActivities(Class<T> type)
425450
throws StreamException {
426451
return getEnrichedCustomActivities(

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,104 @@ public void testGetActivitiesUrlParameters() throws Exception {
220220
assert url.contains("discard_actors=actor4%7Cactor5") : "URL should contain pipe-separated actors, got: " + url;
221221
assert url.contains("discard_actors_sep=%7C") : "URL should contain discard_actors_sep, got: " + url;
222222
}
223+
224+
@Test
225+
public void testGetEnrichedActivitiesWithDiscardActors() throws Exception {
226+
if (apiKey == null || secret == null) {
227+
System.out.println("Skipping testGetEnrichedActivitiesWithDiscardActors - API credentials not set");
228+
return;
229+
}
230+
231+
Client client =
232+
Client.builder(apiKey, secret)
233+
.httpClient(new OKHTTPClientAdapter(new OkHttpClient()))
234+
.build();
235+
236+
FlatFeed feed = client.flatFeed("flat", "test-enriched-discard");
237+
238+
// Test with just DiscardActors on enriched activities
239+
DiscardActors discardActors = new DiscardActors("actor1", "actor2", "actor3");
240+
List<EnrichedActivity> result1 = feed.getEnrichedActivities(discardActors).join();
241+
assert result1 != null;
242+
243+
// Test with DiscardActors + Limit + EnrichmentFlags
244+
List<String> actors = java.util.Arrays.asList("actor4", "actor5");
245+
DiscardActors discardActors2 = new DiscardActors(actors);
246+
EnrichmentFlags flags = new EnrichmentFlags().withOwnReactions().withReactionCounts();
247+
List<EnrichedActivity> result2 = feed.getEnrichedActivities(
248+
new Limit(10),
249+
flags,
250+
discardActors2
251+
).join();
252+
assert result2 != null;
253+
254+
// Test with all parameters including custom separator
255+
List<EnrichedActivity> result3 = feed.getEnrichedActivities(
256+
new Limit(20),
257+
new Offset(5),
258+
new Filter().refresh(),
259+
new EnrichmentFlags().withRecentReactions(),
260+
new DiscardActors(new String[]{"actor6", "actor7"}, "|")
261+
).join();
262+
assert result3 != null;
263+
}
264+
265+
@Test
266+
public void testGetEnrichedActivitiesUrlParameters() throws Exception {
267+
// Create a mock HTTP client that captures the request URL
268+
AtomicReference<String> capturedUrl = new AtomicReference<>();
269+
270+
// Create a custom OkHttpClient that intercepts requests
271+
OkHttpClient mockClient = new OkHttpClient.Builder()
272+
.addInterceptor(chain -> {
273+
capturedUrl.set(chain.request().url().toString());
274+
// Return a mock response for enriched activities
275+
return new okhttp3.Response.Builder()
276+
.request(chain.request())
277+
.protocol(okhttp3.Protocol.HTTP_1_1)
278+
.code(200)
279+
.message("OK")
280+
.body(okhttp3.ResponseBody.create(
281+
okhttp3.MediaType.parse("application/json"),
282+
"{\"results\":[],\"next\":\"\",\"duration\":\"0ms\"}"
283+
))
284+
.build();
285+
})
286+
.build();
287+
288+
Client client = Client.builder("test-key", "test-secret")
289+
.httpClient(new OKHTTPClientAdapter(mockClient))
290+
.build();
291+
292+
FlatFeed feed = client.flatFeed("flat", "test-enriched-url");
293+
294+
// Test enriched activities with discard_actors
295+
feed.getEnrichedActivities(
296+
new Limit(15),
297+
new EnrichmentFlags().withOwnReactions(),
298+
new DiscardActors("user1", "user2")
299+
).join();
300+
301+
String url = capturedUrl.get();
302+
assert url != null;
303+
304+
// Verify URL contains expected parameters
305+
assert url.contains("limit=15") : "URL should contain limit=15, got: " + url;
306+
assert url.contains("discard_actors=user1,user2") : "URL should contain discard_actors, got: " + url;
307+
assert url.contains("with_own_reactions=true") : "URL should contain enrichment flags, got: " + url;
308+
309+
// Test with custom separator on enriched activities
310+
capturedUrl.set(null);
311+
feed.getEnrichedActivities(
312+
new DiscardActors(new String[]{"userA", "userB", "userC"}, ";")
313+
).join();
314+
315+
url = capturedUrl.get();
316+
assert url != null;
317+
// Note: The semicolon may or may not be URL-encoded depending on the HTTP client
318+
assert (url.contains("discard_actors=userA%3BuserB%3BuserC") || url.contains("discard_actors=userA;userB;userC"))
319+
: "URL should contain semicolon-separated actors, got: " + url;
320+
assert (url.contains("discard_actors_sep=%3B") || url.contains("discard_actors_sep=;"))
321+
: "URL should contain discard_actors_sep, got: " + url;
322+
}
223323
}

0 commit comments

Comments
 (0)