MCPcopy Create free account
hub / github.com/GetStream/stream-cli / deleteMultipleCmd

Function deleteMultipleCmd

pkg/cmd/chat/user/user.go:251–321  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

249}
250
251func deleteMultipleCmd() *cobra.Command {
252 cmd := &cobra.Command{
253 Use: "delete-users --new-channel-user-id [user-id] --hard-delete-users [true|false] --hard-delete-messages [true|false] --hard-delete-conversations [user-id1] [user-id2] ...",
254 Short: "Delete multiple users",
255 Long: heredoc.Doc(`
256 You can delete up to 100 users and optionally all of their channels and
257 messages using this method. First the users are marked deleted synchronously
258 so the user will not be directly visible in the API. Then the process deletes
259 the user and related objects asynchronously by scheduling a task to be handle
260 by the task worker.
261
262 The delete users response contain a task ID which can be polled using the
263 get task endpoint to check the status of the deletions.
264
265 Note: when deleting a user with hard delete, it also required hard deletion
266 for messages and conversations as well!
267 `),
268 Example: heredoc.Doc(`
269 # Soft delete users with ids 'my-user-1' and 'my-user-2'
270 $ stream-cli chat delete-users my-user-1 my-user-2
271 > Successfully initiated user deletion. Task id: bf1c2d1b-04d6-4e67-873c-5b3ade478b0a
272 # Waiting for it to succeed
273 $ stream-cli chat watch bf1c2d1b-04d6-4e67-873c-5b3ade478b0a
274 > Async operation completed successfully.
275
276 # Hard delete users with ids 'my-user-3' and 'my-user-4'
277 $ stream-cli chat delete-users --hard-delete-users --hard-delete-messages --hard-delete-conversations my-user-3 my-user-4
278 > Successfully initiated user deletion. Task id: 71516d9a-0764-4aa8-b017-8d2a99748e16
279
280 # Waiting for it to succeed
281 $ stream-cli chat watch 71516d9a-0764-4aa8-b017-8d2a99748e16
282 > Async operation completed successfully.
283 `),
284 RunE: func(cmd *cobra.Command, args []string) error {
285 c, err := config.GetConfig(cmd).GetClient(cmd)
286 if err != nil {
287 return err
288 }
289
290 usersHardDel, _ := cmd.Flags().GetBool("hard-delete-users")
291 msgHardDel, _ := cmd.Flags().GetBool("hard-delete-messages")
292 convHardDel, _ := cmd.Flags().GetBool("hard-delete-conversations")
293 newChannelOwnerID, _ := cmd.Flags().GetString("new-channel-owner-id")
294
295 task, err := c.DeleteUsers(cmd.Context(), args, stream.DeleteUserOptions{
296 User: getDeleteType(usersHardDel),
297 Messages: getDeleteType(msgHardDel),
298 Conversations: getDeleteType(convHardDel),
299 NewChannelOwnerID: newChannelOwnerID,
300 })
301 if err != nil {
302 return err
303 }
304
305 if task.TaskID != "" {
306 cmd.Printf("Successfully initiated user deletion. Task id: %s\n", task.TaskID)
307 return nil
308 } else {

Callers 1

NewCmdsFunction · 0.85

Calls 4

GetConfigFunction · 0.92
getDeleteTypeFunction · 0.85
GetClientMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected