Add GetConversations()
This commit is contained in:
20
chat.go
20
chat.go
@ -422,19 +422,29 @@ func (k *Keybase) DeleteByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID)
|
||||
}
|
||||
|
||||
// GetConversations returns a list of all conversations. Optionally, you can filter by unread
|
||||
func (k *Keybase) GetConversations(unreadOnly bool) (SendResponse, error) {
|
||||
var r SendResponse
|
||||
func (k *Keybase) GetConversations(unreadOnly bool) ([]chat1.ConvSummary, error) {
|
||||
var r Inbox
|
||||
|
||||
opts := SendMessageOptions{
|
||||
UnreadOnly: unreadOnly,
|
||||
}
|
||||
|
||||
r, err := k.SendMessage("list", opts)
|
||||
arg := newSendMessageArg(opts)
|
||||
arg.Method = "list"
|
||||
|
||||
jsonBytes, _ := json.Marshal(arg)
|
||||
|
||||
cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes))
|
||||
if err != nil {
|
||||
return r, err
|
||||
return []chat1.ConvSummary{}, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
err = json.Unmarshal(cmdOut, &r)
|
||||
if err != nil {
|
||||
return []chat1.ConvSummary{}, err
|
||||
}
|
||||
|
||||
return r.Result.Convs, nil
|
||||
}
|
||||
|
||||
// ChatList returns a list of all conversations.
|
||||
|
||||
11
types.go
11
types.go
@ -76,6 +76,17 @@ func newSendMessageArg(options SendMessageOptions) sendMessageArg {
|
||||
}
|
||||
}
|
||||
|
||||
// Result holds the result porstion of a `list` method sent to the API
|
||||
type Result struct {
|
||||
Convs []chat1.ConvSummary `json:"conversations"`
|
||||
}
|
||||
|
||||
// Inbox holds the results of a `list`method sent to the API
|
||||
type Inbox struct {
|
||||
Result Result `json:"result"`
|
||||
Error *Error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// SendResponse holds the data returned by the send method in the API
|
||||
type SendResponse struct {
|
||||
Result chat1.SendRes `json:"result"`
|
||||
|
||||
Reference in New Issue
Block a user