-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_conv_info.go
125 lines (112 loc) · 3.61 KB
/
cmd_chat_conv_info.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package client
import (
"fmt"
"os"
"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"
isatty "github.com/mattn/go-isatty"
context "golang.org/x/net/context"
)
type CmdChatConvInfo struct {
libkb.Contextified
resolvingRequest chatConversationResolvingRequest
hasTTY bool
}
func NewCmdChatConvInfoRunner(g *libkb.GlobalContext) *CmdChatConvInfo {
return &CmdChatConvInfo{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatConvInfo(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "conv-info",
Usage: "Get information about a conversation",
ArgumentHelp: "[conversation]",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatConvInfoRunner(g), "conv-info", c)
cl.SetNoStandalone()
cl.SetLogForward(libcmdline.LogForwardNone)
},
Flags: getConversationResolverFlags(),
}
}
func resolveToConversation(g *libkb.GlobalContext, resolvingRequest chatConversationResolvingRequest,
hasTTY bool) (resolver *chatConversationResolver, res *chat1.ConversationLocal, err error) {
ui := NewChatCLIUI(g)
protocols := []rpc.Protocol{
chat1.ChatUiProtocol(ui),
}
if err := RegisterProtocolsWithContext(protocols, g); err != nil {
return nil, nil, err
}
// if no tlfname specified, request one
if resolvingRequest.TlfName == "" {
resolvingRequest.TlfName, err = g.UI.GetTerminalUI().Prompt(PromptDescriptorEnterChatTLFName,
"Specify a team name, a single receiving user, or a comma-separated list of users (e.g. alice,bob,charlie) to continue: ")
if err != nil {
return nil, nil, err
}
if resolvingRequest.TlfName == "" {
return nil, nil, fmt.Errorf("no user or team name specified")
}
}
if err = annotateResolvingRequest(g, &resolvingRequest); err != nil {
return nil, nil, err
}
resolver, err = newChatConversationResolver(g)
if err != nil {
return nil, nil, err
}
conversation, _, err := resolver.Resolve(context.TODO(), resolvingRequest, chatConversationResolvingBehavior{
CreateIfNotExists: false,
MustNotExist: false,
Interactive: hasTTY,
IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI,
})
switch err.(type) {
case nil:
case libkb.ResolutionError:
return nil, nil, fmt.Errorf("could not resolve `%s` into Keybase user(s) or a team", resolvingRequest.TlfName)
default:
return nil, nil, err
}
return resolver, conversation, nil
}
func (c *CmdChatConvInfo) Run() error {
_, conv, err := resolveToConversation(c.G(), c.resolvingRequest, c.hasTTY)
if err != nil {
return err
}
info := conv.Info
dui := c.G().UI.GetDumbOutputUI()
var topicType string
if info.Triple.TopicType != chat1.TopicType_CHAT {
topicType = fmt.Sprintf(" (%s)", info.Triple.TopicType)
}
_, err = dui.Printf("ConversationName: %s%s\nConversationID: %v\nConvIDShort: %v\n",
utils.FormatConversationName(info, c.G().Env.GetUsername().String()), topicType, info.Id, info.Id.DbShortFormString())
return err
}
func (c *CmdChatConvInfo) ParseArgv(ctx *cli.Context) (err error) {
c.hasTTY = isatty.IsTerminal(os.Stdin.Fd())
var tlfName string
// Get the TLF name from the first position arg
if len(ctx.Args()) >= 1 {
tlfName = ctx.Args().Get(0)
}
if c.resolvingRequest, err = parseConversationResolvingRequest(ctx, tlfName); err != nil {
return err
}
return nil
}
func (c *CmdChatConvInfo) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}