github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/client/cmd_chat_delete_channel.go (about) 1 package client 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/keybase/cli" 8 "github.com/keybase/client/go/chat/utils" 9 "github.com/keybase/client/go/libcmdline" 10 "github.com/keybase/client/go/libkb" 11 "github.com/keybase/client/go/protocol/chat1" 12 "github.com/keybase/client/go/protocol/keybase1" 13 "github.com/keybase/go-framed-msgpack-rpc/rpc" 14 ) 15 16 type CmdChatDeleteChannel struct { 17 libkb.Contextified 18 19 resolvingRequest chatConversationResolvingRequest 20 } 21 22 func NewCmdChatDeleteChannelRunner(g *libkb.GlobalContext) *CmdChatDeleteChannel { 23 return &CmdChatDeleteChannel{ 24 Contextified: libkb.NewContextified(g), 25 } 26 } 27 28 func newCmdChatDeleteChannel(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command { 29 return cli.Command{ 30 Name: "delete-channel", 31 Usage: "Delete a channel", 32 ArgumentHelp: "<team name> <channel name>", 33 Action: func(c *cli.Context) { 34 cl.ChooseCommand(NewCmdChatDeleteChannelRunner(g), "delete-channel", c) 35 cl.SetLogForward(libcmdline.LogForwardNone) 36 }, 37 Flags: mustGetChatFlags("topic-type"), 38 } 39 } 40 41 func (c *CmdChatDeleteChannel) Run() error { 42 ui := NewChatCLIUI(c.G()) 43 protocols := []rpc.Protocol{ 44 chat1.ChatUiProtocol(ui), 45 } 46 if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil { 47 return err 48 } 49 50 resolver, err := newChatConversationResolver(c.G()) 51 if err != nil { 52 return err 53 } 54 55 ctx := context.Background() 56 conv, _, err := resolver.Resolve(ctx, c.resolvingRequest, chatConversationResolvingBehavior{ 57 CreateIfNotExists: false, 58 MustNotExist: false, 59 Interactive: false, 60 IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI, 61 }) 62 if err != nil { 63 return err 64 } 65 66 _, err = resolver.ChatClient.DeleteConversationLocal(ctx, chat1.DeleteConversationLocalArg{ 67 ConvID: conv.GetConvID(), 68 ChannelName: c.resolvingRequest.TopicName, 69 }) 70 if err != nil { 71 return err 72 } 73 74 return nil 75 } 76 77 func (c *CmdChatDeleteChannel) ParseArgv(ctx *cli.Context) (err error) { 78 if len(ctx.Args()) != 2 { 79 return fmt.Errorf("wrong number of arguments") 80 } 81 teamName := ctx.Args().Get(0) 82 topicName := ctx.Args().Get(1) 83 84 if c.resolvingRequest, err = parseConversationResolvingRequest(ctx, teamName); err != nil { 85 return err 86 } 87 88 // Force team for now 89 c.resolvingRequest.MembersType = chat1.ConversationMembersType_TEAM 90 c.resolvingRequest.Visibility = keybase1.TLFVisibility_PRIVATE 91 c.resolvingRequest.TopicName = utils.SanitizeTopicName(topicName) 92 93 return nil 94 } 95 96 func (c *CmdChatDeleteChannel) GetUsage() libkb.Usage { 97 return libkb.Usage{ 98 Config: true, 99 API: true, 100 } 101 }