Skip to content

Commit

Permalink
feat: add ability to delete/restore channels when deactivate/reactiva…
Browse files Browse the repository at this point in the history
…te users (#244)
  • Loading branch information
thesyncim authored Mar 3, 2023
1 parent 91e8556 commit e60d9f4
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (c *Client) ExportUser(ctx context.Context, targetID string) (*ExportUserRe

type deactivateUserOptions struct {
MarkMessagesDeleted bool `json:"mark_messages_deleted"`
MarkChannelsDeleted bool `json:"mark_channels_deleted"`
CreatedByID string `json:"created_by_id"`
}

Expand All @@ -262,6 +263,12 @@ func DeactivateUserWithMarkMessagesDeleted() func(*deactivateUserOptions) {
}
}

func DeactivateUserWithMarkChannelsDeleted() func(*deactivateUserOptions) {
return func(opt *deactivateUserOptions) {
opt.MarkChannelsDeleted = true
}
}

func DeactivateUserWithCreatedBy(userID string) func(*deactivateUserOptions) {
return func(opt *deactivateUserOptions) {
opt.CreatedByID = userID
Expand All @@ -286,8 +293,34 @@ func (c *Client) DeactivateUser(ctx context.Context, targetID string, options ..
return &resp, err
}

type deactivateUsersOptions struct {
UserIDs []string `json:"user_ids"`
deactivateUserOptions
}

// DeactivateUsers deactivates the users with the given target user IDs.
func (c *Client) DeactivateUsers(ctx context.Context, targetIDs []string, options ...DeactivateUserOptions) (*Response, error) {
if len(targetIDs) == 0 {
return nil, errors.New("target IDs is empty")
}

opts := &deactivateUsersOptions{
UserIDs: targetIDs,
}
for _, fn := range options {
fn(&opts.deactivateUserOptions)
}

p := path.Join("users", "deactivate")

var resp Response
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
return &resp, err
}

type reactivateUserOptions struct {
RestoreMessages bool `json:"restore_messages"`
RestoreChannels bool `json:"restore_channels"`
Name string `json:"name"`
CreatedByID string `json:"created_by_id"`
}
Expand All @@ -300,6 +333,12 @@ func ReactivateUserWithRestoreMessages() func(*reactivateUserOptions) {
}
}

func ReactivateUserWithRestoreChannels() func(*reactivateUserOptions) {
return func(opt *reactivateUserOptions) {
opt.RestoreChannels = true
}
}

func ReactivateUserWithCreatedBy(userID string) func(*reactivateUserOptions) {
return func(opt *reactivateUserOptions) {
opt.CreatedByID = userID
Expand Down Expand Up @@ -330,6 +369,31 @@ func (c *Client) ReactivateUser(ctx context.Context, targetID string, options ..
return &resp, err
}

type reactivateUsersOptions struct {
UserIDs []string `json:"user_ids"`
reactivateUserOptions
}

// ReactivateUsers reactivates deactivated users with the given target user IDs.
func (c *Client) ReactivateUsers(ctx context.Context, targetIDs []string, options ...ReactivateUserOptions) (*Response, error) {
if len(targetIDs) == 0 {
return nil, errors.New("target IDs is empty")
}

opts := &reactivateUsersOptions{
UserIDs: targetIDs,
}
for _, fn := range options {
fn(&opts.reactivateUserOptions)
}

p := path.Join("users", "reactivate")

var resp Response
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
return &resp, err
}

type deleteUserOptions struct {
MarkMessagesDeleted string
HardDelete string
Expand Down

0 comments on commit e60d9f4

Please sign in to comment.