Skip to content
Open
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
41 changes: 41 additions & 0 deletions docs/stream-cli_chat_unmute-channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## stream-cli chat unmute-channel

Unmute a channel for a user

### Synopsis

Unmutes a previously muted channel for a specific user.


```
stream-cli chat unmute-channel --type [channel-type] --id [channel-id] --user-id [user-id] [flags]
```

### Examples

```
# Unmute the 'redteam' channel for user 'john'
$ stream-cli chat unmute-channel --type messaging --id redteam --user-id john

```

### Options

```
-h, --help help for unmute-channel
-i, --id string [required] Channel ID
-t, --type string [required] Channel type such as 'messaging'
-u, --user-id string [required] User ID
```

### Options inherited from parent commands

```
--app string [optional] Application name to use as it's defined in the configuration file
--config string [optional] Explicit config file path
```

### SEE ALSO

* [stream-cli chat](stream-cli_chat.md) - Allows you to interact with your Chat applications

45 changes: 45 additions & 0 deletions pkg/cmd/chat/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewCmds() []*cobra.Command {
assignRoleCmd(),
hideCmd(),
showCmd(),
unmuteChannelCmd(),
}
}

Expand Down Expand Up @@ -610,3 +611,47 @@ func showCmd() *cobra.Command {

return cmd
}

func unmuteChannelCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "unmute-channel --type [channel-type] --id [channel-id] --user-id [user-id]",
Short: "Unmute a channel for a user",
Long: heredoc.Doc(`
Unmutes a previously muted channel for a specific user.
`),
Example: heredoc.Doc(`
# Unmute the 'redteam' channel for user 'john'
$ stream-cli chat unmute-channel --type messaging --id redteam --user-id john
`),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := config.GetConfig(cmd).GetClient(cmd)
if err != nil {
return err
}

typ, _ := cmd.Flags().GetString("type")
id, _ := cmd.Flags().GetString("id")
user, _ := cmd.Flags().GetString("user-id")

ch := client.Channel(typ, id)
_, err = ch.Unmute(cmd.Context(), user)
if err != nil {
return err
}

cmd.Printf("Successfully unmuted channel [%s] for user [%s]\n", id, user)
return nil
},
}

fl := cmd.Flags()
fl.StringP("type", "t", "", "[required] Channel type such as 'messaging'")
fl.StringP("id", "i", "", "[required] Channel ID")
fl.StringP("user-id", "u", "", "[required] User ID")

_ = cmd.MarkFlagRequired("type")
_ = cmd.MarkFlagRequired("id")
_ = cmd.MarkFlagRequired("user-id")

return cmd
}
35 changes: 35 additions & 0 deletions pkg/cmd/chat/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,38 @@ func TestHideAndShowChannel(t *testing.T) {
require.NoError(t, err)
require.Contains(t, cmd.OutOrStdout().(*bytes.Buffer).String(), "Successfully shown channel")
}

func TestUnmuteChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
u := test.CreateUser()

t.Cleanup(func() {
test.DeleteChannel(ch)
test.DeleteUser(u)
})

// Add user to channel
cmd.SetArgs([]string{"add-members", "-t", "messaging", "-i", ch, u})
_, err := cmd.ExecuteC()
require.NoError(t, err)

// Unmute the channel for the user
cmd.SetArgs([]string{"unmute-channel", "-t", "messaging", "-i", ch, "-u", u})
_, err = cmd.ExecuteC()
require.NoError(t, err)

// Check that output contains success message
out := cmd.OutOrStdout().(*bytes.Buffer).String()
require.Contains(t, out, "Successfully unmuted channel")

// Verify the mute was removed
client := test.InitClient()
ctx := context.Background()
userResp, err := client.QueryUsers(ctx, &stream.QueryOption{
Filter: map[string]interface{}{"id": u},
})
require.NoError(t, err)
require.Len(t, userResp.Users, 1)
require.Empty(t, userResp.Users[0].ChannelMutes)
}