Skip to content
Draft
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
162 changes: 162 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1875,4 +1875,166 @@ public static ChannelMemberPartialUpdateRequest unarchive(
public static MarkDeliveredRequest markDelivered() {
return new MarkDeliveredRequest();
}

/** Channel batch operation types */
public enum ChannelBatchOperation {
@JsonProperty("addMembers")
ADD_MEMBERS,
@JsonProperty("removeMembers")
REMOVE_MEMBERS,
@JsonProperty("inviteMembers")
INVITE_MEMBERS,
@JsonProperty("assignRoles")
ASSIGN_ROLES,
@JsonProperty("addModerators")
ADD_MODERATORS,
@JsonProperty("demoteModerators")
DEMOTE_MODERATORS,
@JsonProperty("hide")
HIDE,
@JsonProperty("show")
SHOW,
@JsonProperty("archive")
ARCHIVE,
@JsonProperty("unarchive")
UNARCHIVE,
@JsonProperty("updateData")
UPDATE_DATA,
@JsonProperty("addFilterTags")
ADD_FILTER_TAGS,
@JsonProperty("removeFilterTags")
REMOVE_FILTER_TAGS
}

/** Represents a member in batch operations */
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ChannelBatchMemberRequest {
@NotNull
@JsonProperty("user_id")
private String userId;

@Nullable
@JsonProperty("channel_role")
private String channelRole;
}

/** Represents data that can be updated on channels in batch */
@Data
@NoArgsConstructor
public static class ChannelDataUpdate {
@Nullable
@JsonProperty("frozen")
private Boolean frozen;

@Nullable
@JsonProperty("disabled")
private Boolean disabled;

@Nullable
@JsonProperty("custom")
private Map<String, Object> custom;

@Nullable
@JsonProperty("team")
private String team;

@Nullable
@JsonProperty("config_overrides")
private Map<String, Object> configOverrides;

@Nullable
@JsonProperty("auto_translation_enabled")
private Boolean autoTranslationEnabled;

@Nullable
@JsonProperty("auto_translation_language")
private String autoTranslationLanguage;
}

/** Represents filters for batch channel updates */
@Data
@NoArgsConstructor
public static class ChannelsBatchFilters {
@Nullable
@JsonProperty("cids")
private Object cids;

@Nullable
@JsonProperty("types")
private Object types;

@Nullable
@JsonProperty("filter_tags")
private Object filterTags;
}

/** Represents options for batch channel updates */
@Data
@NoArgsConstructor
public static class ChannelsBatchOptions {
@NotNull
@JsonProperty("operation")
private ChannelBatchOperation operation;

@NotNull
@JsonProperty("filter")
private ChannelsBatchFilters filter;

@Nullable
@JsonProperty("members")
private List<ChannelBatchMemberRequest> members;

@Nullable
@JsonProperty("data")
private ChannelDataUpdate data;

@Nullable
@JsonProperty("filter_tags_update")
private List<String> filterTagsUpdate;
}

@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
public static class ChannelsBatchUpdateRequest
extends StreamRequest<ChannelsBatchUpdateResponse> {
@NotNull private ChannelsBatchOptions options;

@Override
protected Call<ChannelsBatchUpdateResponse> generateCall(Client client) throws StreamException {
return client.create(ChannelService.class).updateBatch(this.options);
}
}

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class ChannelsBatchUpdateResponse extends StreamResponseObject {
@NotNull
@JsonProperty("task_id")
private String taskId;
}

/**
* Creates a batch update request
*
* @param options the batch update options
* @return the created request
*/
@NotNull
public static ChannelsBatchUpdateRequest updateBatch(@NotNull ChannelsBatchOptions options) {
return new ChannelsBatchUpdateRequest(options);
}

/**
* Returns a ChannelBatchUpdater instance for batch channel operations.
*
* @return ChannelBatchUpdater instance
*/
@NotNull
public static ChannelBatchUpdater channelBatchUpdater() {
return new ChannelBatchUpdater();
}
}
230 changes: 230 additions & 0 deletions src/main/java/io/getstream/chat/java/models/ChannelBatchUpdater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package io.getstream.chat.java.models;

import io.getstream.chat.java.models.Channel.*;
import java.util.List;
import org.jetbrains.annotations.NotNull;

/** Provides convenience methods for batch channel operations. */
public class ChannelBatchUpdater {

/**
* Adds members to channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members to add
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest addMembers(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.ADD_MEMBERS);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Removes members from channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members to remove
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest removeMembers(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.REMOVE_MEMBERS);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Invites members to channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members to invite
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest inviteMembers(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.INVITE_MEMBERS);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Adds moderators to channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members to add as moderators
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest addModerators(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.ADD_MODERATORS);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Removes moderator role from members in channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members to demote from moderators
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest demoteModerators(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.DEMOTE_MODERATORS);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Assigns roles to members in channels matching the filter.
*
* @param filter the filter to match channels
* @param members list of members with roles to assign
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest assignRoles(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.ASSIGN_ROLES);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Hides channels matching the filter for the specified members.
*
* @param filter the filter to match channels
* @param members list of members for whom to hide channels
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest hide(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.HIDE);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Shows channels matching the filter for the specified members.
*
* @param filter the filter to match channels
* @param members list of members for whom to show channels
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest show(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.SHOW);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Archives channels matching the filter for the specified members.
*
* @param filter the filter to match channels
* @param members list of members for whom to archive channels
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest archive(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.ARCHIVE);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Unarchives channels matching the filter for the specified members.
*
* @param filter the filter to match channels
* @param members list of members for whom to unarchive channels
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest unarchive(
@NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.UNARCHIVE);
options.setFilter(filter);
options.setMembers(members);
return Channel.updateBatch(options);
}

/**
* Updates data on channels matching the filter.
*
* @param filter the filter to match channels
* @param data channel data to update
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest updateData(
@NotNull ChannelsBatchFilters filter, @NotNull ChannelDataUpdate data) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.UPDATE_DATA);
options.setFilter(filter);
options.setData(data);
return Channel.updateBatch(options);
}

/**
* Adds filter tags to channels matching the filter.
*
* @param filter the filter to match channels
* @param tags list of filter tags to add
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest addFilterTags(
@NotNull ChannelsBatchFilters filter, @NotNull List<String> tags) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.ADD_FILTER_TAGS);
options.setFilter(filter);
options.setFilterTagsUpdate(tags);
return Channel.updateBatch(options);
}

/**
* Removes filter tags from channels matching the filter.
*
* @param filter the filter to match channels
* @param tags list of filter tags to remove
* @return the batch update request
*/
@NotNull
public ChannelsBatchUpdateRequest removeFilterTags(
@NotNull ChannelsBatchFilters filter, @NotNull List<String> tags) {
ChannelsBatchOptions options = new ChannelsBatchOptions();
options.setOperation(ChannelBatchOperation.REMOVE_FILTER_TAGS);
options.setFilter(filter);
options.setFilterTagsUpdate(tags);
return Channel.updateBatch(options);
}
}
Loading
Loading