-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_listchannels.go
105 lines (91 loc) · 2.32 KB
/
cmd_chat_listchannels.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
104
105
package client
import (
"context"
"encoding/json"
"fmt"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
)
type CmdChatListChannels struct {
libkb.Contextified
tlfName string
topicType chat1.TopicType
json bool
}
func NewCmdChatListChannelsRunner(g *libkb.GlobalContext) *CmdChatListChannels {
return &CmdChatListChannels{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatListChannels(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
flags := mustGetChatFlags("topic-type")
flags = append(flags, cli.BoolFlag{
Name: "j, json",
Usage: "Output channels as JSON",
})
return cli.Command{
Name: "list-channels",
Usage: "List of channels on a team",
ArgumentHelp: "<team name>",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatListChannelsRunner(g), "list-channels", c)
},
Flags: flags,
}
}
func (c *CmdChatListChannels) Run() error {
ui := c.G().UI.GetTerminalUI()
chatClient, err := GetChatLocalClient(c.G())
if err != nil {
return err
}
ctx := context.Background()
listRes, err := chatClient.GetTLFConversationsLocal(ctx, chat1.GetTLFConversationsLocalArg{
TlfName: c.tlfName,
TopicType: c.topicType,
MembersType: chat1.ConversationMembersType_TEAM,
})
if err != nil {
return err
}
if c.json {
b, err := json.Marshal(listRes)
if err != nil {
return err
}
ui.Printf("%s\n", string(b))
return nil
}
ui.Printf("Listing channels on %s:\n\n", c.tlfName)
for _, c := range listRes.Convs {
convLine := fmt.Sprintf("#%s", c.Channel)
if c.Headline != "" {
convLine += fmt.Sprintf(" [%s]", c.Headline)
}
if c.CreatorInfo != nil {
convLine += fmt.Sprintf(" (created by: %s on: %s)", c.CreatorInfo.Username,
c.CreatorInfo.Ctime.Time().Format("2006-01-02"))
}
ui.Printf("%s\n", convLine)
}
return nil
}
func (c *CmdChatListChannels) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) != 1 {
return fmt.Errorf("incorrect usage")
}
c.tlfName = ctx.Args().Get(0)
if c.topicType, err = parseConversationTopicType(ctx); err != nil {
return err
}
c.json = ctx.Bool("json")
return nil
}
func (c *CmdChatListChannels) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}