diff --git a/docs/stream-cli_chat_unmute-channel.md b/docs/stream-cli_chat_unmute-channel.md new file mode 100644 index 0000000..a15044a --- /dev/null +++ b/docs/stream-cli_chat_unmute-channel.md @@ -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 + diff --git a/pkg/cmd/chat/channel/channel.go b/pkg/cmd/chat/channel/channel.go index 3887ad0..386b9c1 100644 --- a/pkg/cmd/chat/channel/channel.go +++ b/pkg/cmd/chat/channel/channel.go @@ -28,6 +28,7 @@ func NewCmds() []*cobra.Command { assignRoleCmd(), hideCmd(), showCmd(), + unmuteChannelCmd(), } } @@ -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 +} diff --git a/pkg/cmd/chat/channel/channel_test.go b/pkg/cmd/chat/channel/channel_test.go index fd300a7..aad805e 100644 --- a/pkg/cmd/chat/channel/channel_test.go +++ b/pkg/cmd/chat/channel/channel_test.go @@ -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) +}