Skip to content

Commit e60d9f4

Browse files
authored
feat: add ability to delete/restore channels when deactivate/reactivate users (#244)
1 parent 91e8556 commit e60d9f4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

user.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ func (c *Client) ExportUser(ctx context.Context, targetID string) (*ExportUserRe
251251

252252
type deactivateUserOptions struct {
253253
MarkMessagesDeleted bool `json:"mark_messages_deleted"`
254+
MarkChannelsDeleted bool `json:"mark_channels_deleted"`
254255
CreatedByID string `json:"created_by_id"`
255256
}
256257

@@ -262,6 +263,12 @@ func DeactivateUserWithMarkMessagesDeleted() func(*deactivateUserOptions) {
262263
}
263264
}
264265

266+
func DeactivateUserWithMarkChannelsDeleted() func(*deactivateUserOptions) {
267+
return func(opt *deactivateUserOptions) {
268+
opt.MarkChannelsDeleted = true
269+
}
270+
}
271+
265272
func DeactivateUserWithCreatedBy(userID string) func(*deactivateUserOptions) {
266273
return func(opt *deactivateUserOptions) {
267274
opt.CreatedByID = userID
@@ -286,8 +293,34 @@ func (c *Client) DeactivateUser(ctx context.Context, targetID string, options ..
286293
return &resp, err
287294
}
288295

296+
type deactivateUsersOptions struct {
297+
UserIDs []string `json:"user_ids"`
298+
deactivateUserOptions
299+
}
300+
301+
// DeactivateUsers deactivates the users with the given target user IDs.
302+
func (c *Client) DeactivateUsers(ctx context.Context, targetIDs []string, options ...DeactivateUserOptions) (*Response, error) {
303+
if len(targetIDs) == 0 {
304+
return nil, errors.New("target IDs is empty")
305+
}
306+
307+
opts := &deactivateUsersOptions{
308+
UserIDs: targetIDs,
309+
}
310+
for _, fn := range options {
311+
fn(&opts.deactivateUserOptions)
312+
}
313+
314+
p := path.Join("users", "deactivate")
315+
316+
var resp Response
317+
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
318+
return &resp, err
319+
}
320+
289321
type reactivateUserOptions struct {
290322
RestoreMessages bool `json:"restore_messages"`
323+
RestoreChannels bool `json:"restore_channels"`
291324
Name string `json:"name"`
292325
CreatedByID string `json:"created_by_id"`
293326
}
@@ -300,6 +333,12 @@ func ReactivateUserWithRestoreMessages() func(*reactivateUserOptions) {
300333
}
301334
}
302335

336+
func ReactivateUserWithRestoreChannels() func(*reactivateUserOptions) {
337+
return func(opt *reactivateUserOptions) {
338+
opt.RestoreChannels = true
339+
}
340+
}
341+
303342
func ReactivateUserWithCreatedBy(userID string) func(*reactivateUserOptions) {
304343
return func(opt *reactivateUserOptions) {
305344
opt.CreatedByID = userID
@@ -330,6 +369,31 @@ func (c *Client) ReactivateUser(ctx context.Context, targetID string, options ..
330369
return &resp, err
331370
}
332371

372+
type reactivateUsersOptions struct {
373+
UserIDs []string `json:"user_ids"`
374+
reactivateUserOptions
375+
}
376+
377+
// ReactivateUsers reactivates deactivated users with the given target user IDs.
378+
func (c *Client) ReactivateUsers(ctx context.Context, targetIDs []string, options ...ReactivateUserOptions) (*Response, error) {
379+
if len(targetIDs) == 0 {
380+
return nil, errors.New("target IDs is empty")
381+
}
382+
383+
opts := &reactivateUsersOptions{
384+
UserIDs: targetIDs,
385+
}
386+
for _, fn := range options {
387+
fn(&opts.reactivateUserOptions)
388+
}
389+
390+
p := path.Join("users", "reactivate")
391+
392+
var resp Response
393+
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
394+
return &resp, err
395+
}
396+
333397
type deleteUserOptions struct {
334398
MarkMessagesDeleted string
335399
HardDelete string

0 commit comments

Comments
 (0)