/
cmd_chat_report.go
96 lines (80 loc) · 2.11 KB
/
cmd_chat_report.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
package client
import (
"context"
"fmt"
"github.com/keybase/cli"
"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"
)
type CmdChatReport struct {
libkb.Contextified
resolvingRequest chatConversationResolvingRequest
status chat1.ConversationStatus
}
func newCmdChatReport(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "report",
Usage: "Report a conversation (also blocks it)",
ArgumentHelp: "[<conversation>]",
Action: func(c *cli.Context) {
cmd := &CmdChatReport{Contextified: libkb.NewContextified(g)}
cl.ChooseCommand(cmd, "report", c)
},
Flags: getConversationResolverFlags(),
}
}
func (c *CmdChatReport) ParseArgv(ctx *cli.Context) error {
var err error
if len(ctx.Args()) > 1 {
return fmt.Errorf("too many arguments")
}
tlfName := ""
if len(ctx.Args()) == 1 {
tlfName = ctx.Args()[0]
}
c.resolvingRequest, err = parseConversationResolvingRequest(ctx, tlfName)
if err != nil {
return err
}
c.status = chat1.ConversationStatus_REPORTED
return nil
}
func (c *CmdChatReport) Run() error {
ctx := context.Background()
resolver, err := newChatConversationResolver(c.G())
if err != nil {
return err
}
if c.resolvingRequest.TlfName != "" {
if err = annotateResolvingRequest(c.G(), &c.resolvingRequest); err != nil {
return err
}
}
conversation, _, err := resolver.Resolve(ctx, c.resolvingRequest, chatConversationResolvingBehavior{
CreateIfNotExists: false,
MustNotExist: false,
Interactive: false,
IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI,
})
if err != nil {
return err
}
setStatusArg := chat1.SetConversationStatusLocalArg{
ConversationID: conversation.Info.Id,
Status: c.status,
}
_, err = resolver.ChatClient.SetConversationStatusLocal(ctx, setStatusArg)
if err != nil {
return err
}
return nil
}
func (c *CmdChatReport) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
KbKeyring: true,
Config: true,
}
}