-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_mark_as_read.go
94 lines (84 loc) · 2.48 KB
/
cmd_chat_mark_as_read.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
package client
import (
"os"
"github.com/keybase/cli"
"github.com/keybase/client/go/chat/globals"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
isatty "github.com/mattn/go-isatty"
context "golang.org/x/net/context"
)
type CmdChatMarkAsRead struct {
libkb.Contextified
resolvingRequest chatConversationResolvingRequest
hasTTY bool
}
func NewCmdChatMarkAsReadRunner(g *libkb.GlobalContext) *CmdChatMarkAsRead {
return &CmdChatMarkAsRead{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatMarkAsRead(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "mark-as-read",
Usage: "Mark a conversation or entire team as read.",
ArgumentHelp: "[conversation]",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatMarkAsReadRunner(g), "mark-as-read", c)
cl.SetNoStandalone()
cl.SetLogForward(libcmdline.LogForwardNone)
},
Flags: getConversationResolverFlags(),
}
}
func (c *CmdChatMarkAsRead) Run() (err error) {
resolver, conv, err := resolveToConversation(c.G(), c.resolvingRequest, c.hasTTY)
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
if conv.Info.MembersType == chat1.ConversationMembersType_TEAM && conv.Info.TopicName == globals.DefaultTeamTopic {
_, err := resolver.ChatClient.MarkTLFAsReadLocal(context.TODO(), chat1.MarkTLFAsReadLocalArg{
TlfID: conv.Info.Triple.Tlfid,
})
if err != nil {
return err
}
_, err = dui.Printf("Marked all conversations in %q as read.\n", conv.Info.TlfName)
return err
}
_, err = resolver.ChatClient.MarkAsReadLocal(context.TODO(), chat1.MarkAsReadLocalArg{
ConversationID: conv.Info.Id,
MsgID: &conv.ReaderInfo.MaxMsgid,
})
if err != nil {
return err
}
name := conv.Info.TlfName
switch conv.Info.MembersType {
case chat1.ConversationMembersType_TEAM:
name += "#" + conv.Info.TopicName
default:
}
_, err = dui.Printf("Marked %q as read.\n", name)
return err
}
func (c *CmdChatMarkAsRead) 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 *CmdChatMarkAsRead) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}