Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,20 @@ App.getRateLimits().endpoint("QueryChannels").endpoint("SendMessage").request();
User.export(userId).request();
```

**Export users with channel and time filters**

`channelCids` limits the export to those channels (at most 100, not empty). `messagesFrom` is
inclusive and `messagesTo` is exclusive; reactions are selected by the time they were added.
When any filter is set, calls are omitted from the export.

```java
var taskId = ExportUsers.exportUsers(List.of("u1", "u2"))
.channelCids(List.of("messaging:held-channel"))
.messagesFrom(Date.from(Instant.parse("2026-01-01T00:00:00Z")))
.messagesTo(Date.from(Instant.parse("2026-07-01T00:00:00Z")))
.request().getTaskId();
```

**Deactivate user**

```java
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/getstream/chat/java/models/ExportUsers.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package io.getstream.chat.java.models;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.getstream.chat.java.models.framework.StreamRequest;
import io.getstream.chat.java.models.framework.StreamResponseObject;
import io.getstream.chat.java.services.ExportUsersService;
import io.getstream.chat.java.services.framework.Client;
import java.util.Date;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import retrofit2.Call;

@Data
Expand All @@ -28,6 +32,33 @@ public static class ExportUsersRequestData {
@JsonProperty("user_ids")
private List<String> userIds;

/**
* Channel CIDs (type:id) to limit the export to. At most 100 entries; the API rejects an empty
* list. Without it every channel of the users is exported.
*/
@Nullable
@JsonProperty("channel_cids")
@JsonInclude(Include.NON_NULL)
private List<String> channelCids;

/**
* Start of the message window, inclusive: messages created at or after this time are exported.
* Reactions are selected by the time they were added, in the same window.
*/
@Nullable
@JsonProperty("messages_from")
@JsonInclude(Include.NON_NULL)
private Date messagesFrom;

/**
* End of the message window, exclusive: messages created before this time are exported. Must be
* after messagesFrom. When any filter is set, calls are omitted from the export.
*/
@Nullable
@JsonProperty("messages_to")
@JsonInclude(Include.NON_NULL)
private Date messagesTo;

public static class ExportUsersRequest extends StreamRequest<ExportUsers.ExportUsersResponse> {
@Override
protected Call<ExportUsers.ExportUsersResponse> generateCall(Client client) {
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/io/getstream/chat/java/ExportUsersFiltersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.getstream.chat.java;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import io.getstream.chat.java.models.ExportUsers;
import io.getstream.chat.java.models.ExportUsers.ExportUsersRequestData;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.TimeZone;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class ExportUsersFiltersTest {

// Mirrors the visibility and date configuration of DefaultClient's mapper.
private static final ObjectMapper MAPPER =
new ObjectMapper()
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.setDateFormat(
new StdDateFormat()
.withColonInTimeZone(true)
.withTimeZone(TimeZone.getTimeZone("UTC")));

// Serializes the request body exactly as generateCall builds it.
private static String body(ExportUsersRequestData.ExportUsersRequest request) throws Exception {
Method build = request.getClass().getDeclaredMethod("internalBuild");
build.setAccessible(true);
ExportUsersRequestData data = (ExportUsersRequestData) build.invoke(request);
return MAPPER.writeValueAsString(data);
}

@DisplayName("Export users sends channel_cids, messages_from and messages_to when set")
@Test
void whenFiltersSet_thenBodyCarriesThem() throws Exception {
String json =
body(
ExportUsers.exportUsers(Arrays.asList("user-1"))
.channelCids(Arrays.asList("messaging:held-1", "messaging:held-2"))
.messagesFrom(Date.from(Instant.parse("2026-01-01T00:00:00Z")))
.messagesTo(Date.from(Instant.parse("2026-07-01T00:00:00Z"))));

Assertions.assertTrue(
json.contains("\"channel_cids\":[\"messaging:held-1\",\"messaging:held-2\"]"), json);
Assertions.assertTrue(
json.contains("\"messages_from\":\"2026-01-01T00:00:00.000+00:00\""), json);
Assertions.assertTrue(json.contains("\"messages_to\":\"2026-07-01T00:00:00.000+00:00\""), json);
}

@DisplayName("Export users omits the filters when unset")
@Test
void whenFiltersUnset_thenBodyOmitsThem() throws Exception {
String json = body(ExportUsers.exportUsers(Arrays.asList("user-1")));

Assertions.assertEquals("{\"user_ids\":[\"user-1\"]}", json);
}
}
Loading