Add ListMembers methods
This commit is contained in:
47
chat.go
47
chat.go
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
|
"samhofi.us/x/keybase/types/keybase1"
|
||||||
"samhofi.us/x/keybase/types/stellar1"
|
"samhofi.us/x/keybase/types/stellar1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -753,3 +754,49 @@ func (k *Keybase) ClearCommands() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMembers returns member information for a channel or conversation
|
||||||
|
func (k *Keybase) ListMembers(options ListMembersOptions) (keybase1.TeamDetails, error) {
|
||||||
|
type res struct {
|
||||||
|
Result keybase1.TeamDetails `json:"result"`
|
||||||
|
Error *Error `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var r res
|
||||||
|
|
||||||
|
arg := newListMembersArg(options)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMembersOfChannel returns member information for a channel
|
||||||
|
func (k *Keybase) ListMembersOfChannel(channel chat1.ChatChannel) (keybase1.TeamDetails, error) {
|
||||||
|
opts := ListMembersOptions{
|
||||||
|
Channel: channel,
|
||||||
|
}
|
||||||
|
return k.ListMembers(opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMembersOfConversation returns member information for a conversation
|
||||||
|
func (k *Keybase) ListMembersOfConversation(convID chat1.ConvIDStr) (keybase1.TeamDetails, error) {
|
||||||
|
opts := ListMembersOptions{
|
||||||
|
ConversationID: convID,
|
||||||
|
}
|
||||||
|
return k.ListMembers(opts)
|
||||||
|
}
|
||||||
|
|||||||
24
types.go
24
types.go
@ -183,6 +183,30 @@ func newDownloadArg(options DownloadOptions) downloadArg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMembersOptions holds a set of options to be passed to ListMembers
|
||||||
|
type ListMembersOptions struct {
|
||||||
|
Channel chat1.ChatChannel
|
||||||
|
ConversationID chat1.ConvIDStr `json:"conversation_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type listMembersParams struct {
|
||||||
|
Options ListMembersOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
type listMembersArg struct {
|
||||||
|
Method string
|
||||||
|
Params listMembersParams
|
||||||
|
}
|
||||||
|
|
||||||
|
func newListMembersArg(options ListMembersOptions) listMembersArg {
|
||||||
|
return listMembersArg{
|
||||||
|
Method: "listmembers",
|
||||||
|
Params: listMembersParams{
|
||||||
|
Options: options,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// KVOptions holds a set of options to be passed to the KV methods
|
// KVOptions holds a set of options to be passed to the KV methods
|
||||||
type KVOptions struct {
|
type KVOptions struct {
|
||||||
Team *string `json:"team"`
|
Team *string `json:"team"`
|
||||||
|
|||||||
Reference in New Issue
Block a user