Browse Source

Allow TopicType to be specified when calling ChatList

main
Sam 5 years ago
parent
commit
e4cdbc50c9
  1. 58
      chat.go
  2. 25
      types.go

58
chat.go

@ -131,8 +131,12 @@ func (c Chat) Send(message ...string) (ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Message: &mesg{},
}
m.Method = "send" m.Method = "send"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ") m.Params.Options.Message.Body = strings.Join(message, " ")
r, err := chatAPIOut(c.keybase, m) r, err := chatAPIOut(c.keybase, m)
@ -147,8 +151,11 @@ func (c Chat) Edit(messageID int, message ...string) (ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Message: &mesg{},
}
m.Method = "edit" m.Method = "edit"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ") m.Params.Options.Message.Body = strings.Join(message, " ")
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
@ -164,8 +171,11 @@ func (c Chat) React(messageID int, reaction string) (ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Message: &mesg{},
}
m.Method = "reaction" m.Method = "reaction"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = reaction m.Params.Options.Message.Body = reaction
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
@ -182,7 +192,7 @@ func (c Chat) Delete(messageID int) (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "delete" m.Method = "delete"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
r, err := chatAPIOut(c.keybase, m) r, err := chatAPIOut(c.keybase, m)
@ -193,8 +203,14 @@ func (c Chat) Delete(messageID int) (ChatAPI, error) {
} }
// ChatList returns a list of all conversations. // ChatList returns a list of all conversations.
func (k *Keybase) ChatList() (ChatAPI, error) { func (k *Keybase) ChatList(topicType ...string) (ChatAPI, error) {
m := ChatAPI{} m := ChatAPI{
Params: &params{},
}
if len(topicType) > 0 {
m.Params.Options.TopicType = topicType[0]
}
m.Method = "list" m.Method = "list"
r, err := chatAPIOut(k, m) r, err := chatAPIOut(k, m)
@ -208,8 +224,12 @@ func (c Chat) Read(count ...int) (*ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Pagination: &pagination{},
}
m.Method = "read" m.Method = "read"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
if len(count) == 0 { if len(count) == 0 {
m.Params.Options.Pagination.Num = 10 m.Params.Options.Pagination.Num = 10
} else { } else {
@ -232,8 +252,12 @@ func (c *ChatAPI) Next(count ...int) (*ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Pagination: &pagination{},
}
m.Method = "read" m.Method = "read"
m.Params.Options.Channel = c.Result.Messages[0].Msg.Channel m.Params.Options.Channel = &c.Result.Messages[0].Msg.Channel
if len(count) == 0 { if len(count) == 0 {
m.Params.Options.Pagination.Num = c.Result.Pagination.Num m.Params.Options.Pagination.Num = c.Result.Pagination.Num
} else { } else {
@ -259,8 +283,12 @@ func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error) {
m := ChatAPI{ m := ChatAPI{
Params: &params{}, Params: &params{},
} }
m.Params.Options = options{
Pagination: &pagination{},
}
m.Method = "read" m.Method = "read"
m.Params.Options.Channel = c.Result.Messages[0].Msg.Channel m.Params.Options.Channel = &c.Result.Messages[0].Msg.Channel
if len(count) == 0 { if len(count) == 0 {
m.Params.Options.Pagination.Num = c.Result.Pagination.Num m.Params.Options.Pagination.Num = c.Result.Pagination.Num
} else { } else {
@ -285,7 +313,7 @@ func (c Chat) Upload(title string, filepath string) (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "attach" m.Method = "attach"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.Filename = filepath m.Params.Options.Filename = filepath
m.Params.Options.Title = title m.Params.Options.Title = title
@ -302,7 +330,7 @@ func (c Chat) Download(messageID int, filepath string) (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "download" m.Method = "download"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.Output = filepath m.Params.Options.Output = filepath
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
@ -320,7 +348,7 @@ func (c Chat) LoadFlip(messageID int, conversationID string, flipConversationID
Params: &params{}, Params: &params{},
} }
m.Method = "loadflip" m.Method = "loadflip"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.MsgID = messageID m.Params.Options.MsgID = messageID
m.Params.Options.ConversationID = conversationID m.Params.Options.ConversationID = conversationID
m.Params.Options.FlipConversationID = flipConversationID m.Params.Options.FlipConversationID = flipConversationID
@ -339,7 +367,7 @@ func (c Chat) Pin(messageID int) (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "pin" m.Method = "pin"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
r, err := chatAPIOut(c.keybase, m) r, err := chatAPIOut(c.keybase, m)
@ -355,7 +383,7 @@ func (c Chat) Unpin() (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "unpin" m.Method = "unpin"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
r, err := chatAPIOut(c.keybase, m) r, err := chatAPIOut(c.keybase, m)
if err != nil { if err != nil {
@ -370,7 +398,7 @@ func (c Chat) Mark(messageID int) (ChatAPI, error) {
Params: &params{}, Params: &params{},
} }
m.Method = "mark" m.Method = "mark"
m.Params.Options.Channel = c.Channel m.Params.Options.Channel = &c.Channel
m.Params.Options.MessageID = messageID m.Params.Options.MessageID = messageID
r, err := chatAPIOut(c.keybase, m) r, err := chatAPIOut(c.keybase, m)

25
types.go

@ -224,22 +224,23 @@ type Channel struct {
TopicName string `json:"topic_name,omitempty"` TopicName string `json:"topic_name,omitempty"`
} }
type message struct { type mesg struct {
Body string `json:"body"` Body string `json:"body"`
} }
type options struct { type options struct {
Channel Channel `json:"channel"` Channel *Channel `json:"channel,omitempty"`
MessageID int `json:"message_id"` MessageID int `json:"message_id,omitempty"`
Message message `json:"message"` Message *mesg `json:"message,omitempty"`
Pagination pagination `json:"pagination"` Pagination *pagination `json:"pagination,omitempty"`
Filename string `json:"filename,omitempty"` Filename string `json:"filename,omitempty,omitempty"`
Title string `json:"title,omitempty"` Title string `json:"title,omitempty,omitempty"`
Output string `json:"output,omitempty"` Output string `json:"output,omitempty,omitempty"`
ConversationID string `json:"conversation_id"` ConversationID string `json:"conversation_id,omitempty"`
FlipConversationID string `json:"flip_conversation_id"` FlipConversationID string `json:"flip_conversation_id,omitempty"`
MsgID int `json:"msg_id"` MsgID int `json:"msg_id,omitempty"`
GameID string `json:"game_id"` GameID string `json:"game_id,omitempty"`
TopicType string `json:"topic_type,omitempty"`
} }
type params struct { type params struct {
Options options `json:"options"` Options options `json:"options"`

Loading…
Cancel
Save