From 4e3cd22f76269d0cec80b524800bd21180c32154 Mon Sep 17 00:00:00 2001 From: Orhan Erday Date: Fri, 8 Aug 2025 08:03:50 +0300 Subject: [PATCH 1/2] Add unmute-channel feature. --- docs/stream-cli_chat_unmute-channel.md | 38 ++++++++++++++++++++++ pkg/cmd/chat/channel/channel.go | 45 ++++++++++++++++++++++++++ pkg/cmd/chat/channel/channel_test.go | 35 ++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 docs/stream-cli_chat_unmute-channel.md diff --git a/docs/stream-cli_chat_unmute-channel.md b/docs/stream-cli_chat_unmute-channel.md new file mode 100644 index 0000000..2c92cdc --- /dev/null +++ b/docs/stream-cli_chat_unmute-channel.md @@ -0,0 +1,38 @@ +## stream-cli chat unmute-channel + +Unmute a channel for a user + +``` +stream-cli chat unmute-channel --type [channel-type] --id [channel-id] --user-id [user-id] [flags] +``` + +### Synopsis + +Unmutes a previously muted channel for a specific user. + +### Examples + +``` +# Unmute the 'redteam' channel for user 'john' +$ stream-cli chat unmute-channel --type messaging --id redteam --user-id john +``` + +### Options + +``` + -t, --type string [required] Channel type such as 'messaging' + -i, --id string [required] Channel ID + -u, --user-id string [required] User ID + -h, --help help for unmute-channel +``` + +### 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) +} From fa5f96a5618a5475a45d1c5296b3ff821a29b766 Mon Sep 17 00:00:00 2001 From: oerday Date: Mon, 11 Aug 2025 17:02:42 +0300 Subject: [PATCH 2/2] Update stream-cli_chat_unmute-channel.md --- docs/stream-cli_chat_unmute-channel.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/stream-cli_chat_unmute-channel.md b/docs/stream-cli_chat_unmute-channel.md index 2c92cdc..a15044a 100644 --- a/docs/stream-cli_chat_unmute-channel.md +++ b/docs/stream-cli_chat_unmute-channel.md @@ -2,28 +2,30 @@ Unmute a channel for a user -``` -stream-cli chat unmute-channel --type [channel-type] --id [channel-id] --user-id [user-id] [flags] -``` - ### 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 ``` - -t, --type string [required] Channel type such as 'messaging' - -i, --id string [required] Channel ID - -u, --user-id string [required] User ID - -h, --help help for unmute-channel + -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 @@ -36,3 +38,4 @@ $ stream-cli chat unmute-channel --type messaging --id redteam --user-id john ### SEE ALSO * [stream-cli chat](stream-cli_chat.md) - Allows you to interact with your Chat applications +