-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_emojilist.go
83 lines (76 loc) · 1.98 KB
/
cmd_chat_emojilist.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
package client
import (
"fmt"
"time"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
"golang.org/x/net/context"
)
type CmdChatListEmoji struct {
libkb.Contextified
}
func newCmdChatListEmoji(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "emoji-list",
Usage: "List all sendable emojis",
ArgumentHelp: "",
Action: func(c *cli.Context) {
cmd := &CmdChatListEmoji{Contextified: libkb.NewContextified(g)}
cl.ChooseCommand(cmd, "emoji-list", c)
},
}
}
func (c *CmdChatListEmoji) ParseArgv(ctx *cli.Context) error {
return nil
}
func (c *CmdChatListEmoji) Run() error {
ctx := context.Background()
cli, err := GetChatLocalClient(c.G())
if err != nil {
return err
}
res, err := cli.UserEmojis(ctx, chat1.UserEmojisArg{
Opts: chat1.EmojiFetchOpts{
GetCreationInfo: true,
GetAliases: true,
},
ConvID: nil,
})
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
for _, group := range res.Emojis.Emojis {
dui.Printf("Name: %s\n", group.Name)
for _, emoji := range group.Emojis {
var source string
typ, _ := emoji.RemoteSource.Typ()
switch typ {
case chat1.EmojiRemoteSourceTyp_MESSAGE:
source = fmt.Sprintf("convID: %s msgID: %d", emoji.RemoteSource.Message().ConvID,
emoji.RemoteSource.Message().MsgID)
case chat1.EmojiRemoteSourceTyp_STOCKALIAS:
source = emoji.RemoteSource.Stockalias().Text
default:
source = "???"
}
var creator string
var timeStr string
if emoji.CreationInfo != nil {
creator = emoji.CreationInfo.Username
timeStr = emoji.CreationInfo.Time.Time().Format(time.UnixDate)
}
dui.Printf("%s creator: %s time: %s src: %s\n", emoji.Alias, creator, timeStr, source)
}
}
return nil
}
func (c *CmdChatListEmoji) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
KbKeyring: true,
Config: true,
}
}