From 22396f827644d677965e692f45707d946fe8c5d4 Mon Sep 17 00:00:00 2001 From: Sam Hofius Date: Tue, 12 May 2020 01:39:29 -0400 Subject: [PATCH] Add ListConvsOnName --- chat.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/chat.go b/chat.go index 007195e..79a9699 100644 --- a/chat.go +++ b/chat.go @@ -752,3 +752,38 @@ 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 res struct { + Result []chat1.ConvSummary `json:"result"` + Error *Error `json:"error,omitempty"` + } + + var r res + + opts := SendMessageOptions{ + Channel: channel, + } + + arg := newSendMessageArg(opts) + arg.Method = "listconvsonname" + + jsonBytes, _ := json.Marshal(arg) + + cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes)) + if err != nil { + return r.Result, err + } + + err = json.Unmarshal(cmdOut, &r) + if err != nil { + return r.Result, err + } + + if r.Error != nil { + return r.Result, fmt.Errorf("%v", r.Error.Message) + } + + return r.Result, nil +}