-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_default_channels.go
100 lines (90 loc) · 2.44 KB
/
cmd_chat_default_channels.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
package client
import (
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
context "golang.org/x/net/context"
)
type CmdChatDefaultChannels struct {
libkb.Contextified
tlfName string
convs []string
}
func NewCmdChatDefaultChannelsRunner(g *libkb.GlobalContext) *CmdChatDefaultChannels {
return &CmdChatDefaultChannels{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatDefaultChannels(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "default-channels",
Usage: "Set or get the default channels of a team",
ArgumentHelp: "[team]",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatDefaultChannelsRunner(g), "default-channels", c)
cl.SetNoStandalone()
cl.SetLogForward(libcmdline.LogForwardNone)
},
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "channel",
Usage: `Set the given channel name to be a default channels.
New team members will automatically added to this channel.
Can be specified multiple times.`,
},
},
}
}
func (c *CmdChatDefaultChannels) Run() (err error) {
chatClient, err := GetChatLocalClient(c.G())
if err != nil {
return err
}
cli, err := GetTeamsClient(c.G())
if err != nil {
return err
}
teamID, err := cli.GetTeamID(context.Background(), c.tlfName)
if err != nil {
return err
}
if len(c.convs) > 0 { // set channels first
convIDs, err := lookupConvIDsByTopicName(c.G(), c.tlfName, chat1.ConversationMembersType_TEAM, c.convs)
if err != nil {
return err
}
_, err = chatClient.SetDefaultTeamChannelsLocal(context.TODO(), chat1.SetDefaultTeamChannelsLocalArg{
TeamID: teamID,
Convs: convIDs,
})
if err != nil {
return err
}
}
resp, err := chatClient.GetDefaultTeamChannelsLocal(context.TODO(), teamID)
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("Default channels for %s are:\n", c.tlfName)
dui.Printf("\t#general\n")
for _, conv := range resp.Convs {
dui.Printf("\t#%s\n", conv.Channel)
}
return nil
}
func (c *CmdChatDefaultChannels) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) != 1 {
return BadArgsError{"Expected exactly one arg"}
}
c.tlfName = ctx.Args().Get(0)
c.convs = ctx.StringSlice("channel")
return nil
}
func (c *CmdChatDefaultChannels) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}