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