Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a8e68baf4 | |||
| acc3e3ddec | |||
| 22396f8276 | |||
| c9a2bd80bc |
44
chat.go
44
chat.go
@ -37,7 +37,15 @@ func getNewMessages(k *Keybase, subs *subscriptionChannels, execOptions []string
|
||||
execString = append(execString, execOptions...)
|
||||
}
|
||||
for {
|
||||
execCmd := exec.Command(k.Path, execString...)
|
||||
cmd := make([]string, 0)
|
||||
|
||||
if k.HomePath != "" {
|
||||
cmd = append(cmd, "--home", k.HomePath)
|
||||
}
|
||||
|
||||
cmd = append(cmd, execString...)
|
||||
|
||||
execCmd := exec.Command(k.ExePath, cmd...)
|
||||
stdOut, _ := execCmd.StdoutPipe()
|
||||
execCmd.Start()
|
||||
scanner := bufio.NewScanner(stdOut)
|
||||
@ -744,3 +752,37 @@ func (k *Keybase) ListMembersOfConversation(convID chat1.ConvIDStr) (chat1.ChatM
|
||||
}
|
||||
return k.ListMembers(opts)
|
||||
}
|
||||
|
||||
// ListConvsOnName returns a list of all conversations for a chat1.ChatChannel
|
||||
func (k *Keybase) ListConvsOnName(channel chat1.ChatChannel) (*[]chat1.ConvSummary, error) {
|
||||
type result struct {
|
||||
Conversations []chat1.ConvSummary `json:"conversations"`
|
||||
}
|
||||
|
||||
type res struct {
|
||||
Result result `json:"result"`
|
||||
Error *Error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
var r res
|
||||
|
||||
arg := newListConvsOnNameArg(channel)
|
||||
|
||||
jsonBytes, _ := json.Marshal(arg)
|
||||
|
||||
cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(cmdOut, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.Error != nil {
|
||||
return nil, fmt.Errorf("%v", r.Error.Message)
|
||||
}
|
||||
|
||||
return &r.Result.Conversations, nil
|
||||
}
|
||||
|
||||
34
keybase.go
34
keybase.go
@ -21,13 +21,33 @@ const (
|
||||
CHAT string = "chat"
|
||||
)
|
||||
|
||||
// New returns a new Keybase
|
||||
func New(opts ...KeybaseOpt) *Keybase {
|
||||
k := &Keybase{ExePath: "keybase"}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt.apply(k)
|
||||
}
|
||||
|
||||
s := k.status()
|
||||
k.Version = k.version()
|
||||
k.LoggedIn = s.LoggedIn
|
||||
if k.LoggedIn {
|
||||
k.Username = s.Username
|
||||
k.Device = s.Device.Name
|
||||
}
|
||||
|
||||
return k
|
||||
}
|
||||
|
||||
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
||||
// This is deprecated and will be removed in a future update. Use New() instead.
|
||||
func NewKeybase(path ...string) *Keybase {
|
||||
k := &Keybase{}
|
||||
if len(path) < 1 {
|
||||
k.Path = "keybase"
|
||||
k.ExePath = "keybase"
|
||||
} else {
|
||||
k.Path = path[0]
|
||||
k.ExePath = path[0]
|
||||
}
|
||||
|
||||
s := k.status()
|
||||
@ -42,7 +62,15 @@ func NewKeybase(path ...string) *Keybase {
|
||||
|
||||
// Exec executes the given Keybase command
|
||||
func (k *Keybase) Exec(command ...string) ([]byte, error) {
|
||||
out, err := exec.Command(k.Path, command...).Output()
|
||||
cmd := make([]string, 0)
|
||||
|
||||
if k.HomePath != "" {
|
||||
cmd = append(cmd, "--home", k.HomePath)
|
||||
}
|
||||
|
||||
cmd = append(cmd, command...)
|
||||
|
||||
out, err := exec.Command(k.ExePath, cmd...).Output()
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
52
types.go
52
types.go
@ -20,6 +20,37 @@ type RunOptions struct {
|
||||
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
||||
}
|
||||
|
||||
// KeybaseOpt configures a Keybase
|
||||
type KeybaseOpt interface {
|
||||
apply(kb *Keybase)
|
||||
}
|
||||
|
||||
// SetExePath sets the path to the Keybase executable
|
||||
func SetExePath(path string) KeybaseOpt {
|
||||
return setExePath{path}
|
||||
}
|
||||
|
||||
type setExePath struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (o setExePath) apply(kb *Keybase) {
|
||||
kb.ExePath = o.path
|
||||
}
|
||||
|
||||
// SetHomePath sets the path to the Keybase home directory
|
||||
func SetHomePath(path string) KeybaseOpt {
|
||||
return setHomePath{path}
|
||||
}
|
||||
|
||||
type setHomePath struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (o setHomePath) apply(kb *Keybase) {
|
||||
kb.HomePath = o.path
|
||||
}
|
||||
|
||||
type subscriptionType struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
@ -207,6 +238,24 @@ func newListMembersArg(options ListMembersOptions) listMembersArg {
|
||||
}
|
||||
}
|
||||
|
||||
type listConvsOnNameParams struct {
|
||||
Options chat1.ChatChannel
|
||||
}
|
||||
|
||||
type listConvsOnNameArg struct {
|
||||
Method string
|
||||
Params listConvsOnNameParams
|
||||
}
|
||||
|
||||
func newListConvsOnNameArg(channel chat1.ChatChannel) listConvsOnNameArg {
|
||||
return listConvsOnNameArg{
|
||||
Method: "listconvsonname",
|
||||
Params: listConvsOnNameParams{
|
||||
Options: channel,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// KVOptions holds a set of options to be passed to the KV methods
|
||||
type KVOptions struct {
|
||||
Team *string `json:"team"`
|
||||
@ -954,7 +1003,8 @@ type userBlocks struct {
|
||||
|
||||
// Keybase holds basic information about the local Keybase executable
|
||||
type Keybase struct {
|
||||
Path string
|
||||
HomePath string
|
||||
ExePath string
|
||||
Username string
|
||||
LoggedIn bool
|
||||
Version string
|
||||
|
||||
Reference in New Issue
Block a user