Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'add-to-channel' cmd #18877

Merged
merged 2 commits into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go/client/cmd_chat.go
Expand Up @@ -11,6 +11,7 @@ import (

func NewCmdChat(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
subcommands := []cli.Command{
newCmdChatAddToChannel(cl, g),
newCmdChatAPI(cl, g),
newCmdChatAPIListen(cl, g),
newCmdChatDeleteChannel(cl, g),
Expand Down
126 changes: 126 additions & 0 deletions go/client/cmd_chat_addtochannel.go
@@ -0,0 +1,126 @@
// Copyright 2019 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"errors"
"strings"

"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"
"golang.org/x/net/context"
)

type CmdChatAddToChannel struct {
libkb.Contextified
teamName string
channelName string
users []string
topicType chat1.TopicType
}

func NewCmdChatAddToChannelRunner(g *libkb.GlobalContext) *CmdChatAddToChannel {
return &CmdChatAddToChannel{Contextified: libkb.NewContextified(g)}
}

func newCmdChatAddToChannel(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "add-to-channel",
Usage: "Add one or more users to a channel",
ArgumentHelp: "<team> <channel> <usernames>",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatAddToChannelRunner(g), "add-to-channel", c)
cl.SetLogForward(libcmdline.LogForwardNone)
},
Flags: mustGetChatFlags("topic-type"),
Description: chatAddToChannelDoc,
}
}

func (c *CmdChatAddToChannel) Run() error {
ctx := context.TODO()
resolver, err := newChatConversationResolver(c.G())
if err != nil {
return err
}
req := chatConversationResolvingRequest{
TlfName: c.teamName,
TopicName: c.channelName,
TopicType: c.topicType,
MembersType: chat1.ConversationMembersType_TEAM,
Visibility: keybase1.TLFVisibility_PRIVATE,
}
conversation, _, err := resolver.Resolve(ctx, req, chatConversationResolvingBehavior{
CreateIfNotExists: false,
MustNotExist: false,
Interactive: false,
IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI,
})
if err != nil {
return err
}
err = resolver.ChatClient.BulkAddToConv(ctx, chat1.BulkAddToConvArg{
Usernames: c.users,
ConvID: conversation.GetConvID(),
})
if err == nil {
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("Success!\n")
return nil
}
return err
}

func (c *CmdChatAddToChannel) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) != 3 {
return errors.New("add-to-channel takes three arguments")
}

c.teamName = ctx.Args().Get(0)
c.channelName = utils.SanitizeTopicName(ctx.Args().Get(1))

userString := ctx.Args().Get(2)
if len(userString) == 0 {
return errors.New("add-to-channel needs at least one user")
}
users := strings.Split(userString, ",")
for _, user := range users {
if len(user) == 0 {
return errors.New("cannot specify an empty user")
}
c.users = append(c.users, user)
}

c.topicType, err = parseConversationTopicType(ctx)
if err != nil {
return err
}

return nil
}

func (c *CmdChatAddToChannel) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}

const chatAddToChannelDoc = `"keybase chat add-to-channel" allows you to add one or more users to a channel

EXAMPLES:

Add a single keybase user:

keybase chat add-to-channel acme announcements alice

Add a multiple keybase users:

keybase chat add-to-channel acme announcements alice,bob,charlie
`