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
46 changes: 46 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,49 @@ func (ch *Channel) RemoveFilterTags(ctx context.Context, tags []string, message
resp.updateChannel(ch)
return &resp.Response, nil
}

// ChannelBatchOperation represents the type of batch update operation.
type ChannelBatchOperation string

const (
BatchUpdateOperationAddMembers ChannelBatchOperation = "addMembers"
BatchUpdateOperationRemoveMembers ChannelBatchOperation = "removeMembers"
BatchUpdateOperationInvites ChannelBatchOperation = "invites"
BatchUpdateOperationAssignRoles ChannelBatchOperation = "assignRoles"
BatchUpdateOperationAddModerators ChannelBatchOperation = "addModerators"
BatchUpdateOperationDemoteModerators ChannelBatchOperation = "demoteModerators"
BatchUpdateOperationHide ChannelBatchOperation = "hide"
BatchUpdateOperationShow ChannelBatchOperation = "show"
BatchUpdateOperationArchive ChannelBatchOperation = "archive"
BatchUpdateOperationUnarchive ChannelBatchOperation = "unarchive"
BatchUpdateOperationUpdateData ChannelBatchOperation = "updateData"
BatchUpdateOperationAddFilterTags ChannelBatchOperation = "addFilterTags"
BatchUpdateOperationRemoveFilterTags ChannelBatchOperation = "removeFilterTags"
)

// ChannelDataUpdate represents data that can be updated on channels in batch.
type ChannelDataUpdate struct {
Frozen *bool `json:"frozen,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
Team string `json:"team,omitempty"`
ConfigOverrides map[string]interface{} `json:"config_overrides,omitempty"`
AutoTranslationEnabled *bool `json:"auto_translation_enabled,omitempty"`
AutoTranslationLanguage string `json:"auto_translation_language,omitempty"`
}

// ChannelsBatchFilters represents filters for batch channel updates.
type ChannelsBatchFilters struct {
CIDs interface{} `json:"cids,omitempty"`
Types interface{} `json:"types,omitempty"`
FilterTags interface{} `json:"filter_tags,omitempty"`
}

// ChannelsBatchOptions represents options for batch channel updates.
type ChannelsBatchOptions struct {
Operation ChannelBatchOperation `json:"operation"`
Filter ChannelsBatchFilters `json:"filter"`
Members interface{} `json:"members,omitempty"`
Data *ChannelDataUpdate `json:"data,omitempty"`
FilterTagsUpdate []string `json:"filter_tags_update,omitempty"`
}
146 changes: 146 additions & 0 deletions channel_batch_updater.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package stream_chat

import (
"context"
)

// ChannelBatchUpdater provides convenience methods for batch channel operations.
type ChannelBatchUpdater struct {
client *Client
}

// ChannelBatchMemberRequest represents a member in batch operations.
type ChannelBatchMemberRequest struct {
UserID string `json:"user_id"`
ChannelRole string `json:"channel_role,omitempty"`
}

// AddMembers adds members to channels matching the filter.
func (u *ChannelBatchUpdater) AddMembers(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationAddMembers,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// RemoveMembers removes members from channels matching the filter.
func (u *ChannelBatchUpdater) RemoveMembers(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationRemoveMembers,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// InviteMembers invites members to channels matching the filter.
func (u *ChannelBatchUpdater) InviteMembers(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationInvites,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// AddModerators adds moderators to channels matching the filter.
func (u *ChannelBatchUpdater) AddModerators(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationAddModerators,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// DemoteModerators removes moderator role from members in channels matching the filter.
func (u *ChannelBatchUpdater) DemoteModerators(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationDemoteModerators,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// AssignRoles assigns roles to members in channels matching the filter.
func (u *ChannelBatchUpdater) AssignRoles(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationAssignRoles,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// Hide hides channels matching the filter for the specified members.
func (u *ChannelBatchUpdater) Hide(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationHide,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// Show shows channels matching the filter for the specified members.
func (u *ChannelBatchUpdater) Show(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationShow,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// Archive archives channels matching the filter for the specified members.
func (u *ChannelBatchUpdater) Archive(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationArchive,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// Unarchive unarchives channels matching the filter for the specified members.
func (u *ChannelBatchUpdater) Unarchive(ctx context.Context, filter ChannelsBatchFilters, members []ChannelBatchMemberRequest) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationUnarchive,
Filter: filter,
Members: members,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// UpdateData updates data on channels matching the filter.
func (u *ChannelBatchUpdater) UpdateData(ctx context.Context, filter ChannelsBatchFilters, data *ChannelDataUpdate) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationUpdateData,
Filter: filter,
Data: data,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// AddFilterTags adds filter tags to channels matching the filter.
func (u *ChannelBatchUpdater) AddFilterTags(ctx context.Context, filter ChannelsBatchFilters, tags []string) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationAddFilterTags,
Filter: filter,
FilterTagsUpdate: tags,
}
return u.client.UpdateChannelsBatch(ctx, options)
}

// RemoveFilterTags removes filter tags from channels matching the filter.
func (u *ChannelBatchUpdater) RemoveFilterTags(ctx context.Context, filter ChannelsBatchFilters, tags []string) (*AsyncTaskResponse, error) {
options := &ChannelsBatchOptions{
Operation: BatchUpdateOperationRemoveFilterTags,
Filter: filter,
FilterTagsUpdate: tags,
}
return u.client.UpdateChannelsBatch(ctx, options)
}
Loading