From 26e487659c3cf57c933de5fa5d782b11bd3ec2a0 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 16 Feb 2020 15:38:25 -0500 Subject: [PATCH] Ephemeral duration should be optional --- chat.go | 12 ++++++------ types.go | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/chat.go b/chat.go index 7acaad3..937f62d 100644 --- a/chat.go +++ b/chat.go @@ -235,7 +235,7 @@ func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration tim Message: SendMessageBody{ Body: fmt.Sprintf(message, a...), }, - ExplodingLifetime: explodingLifetime{duration}, + ExplodingLifetime: &ExplodingLifetime{duration}, } r, err := k.SendMessage(opts) @@ -255,7 +255,7 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du Message: SendMessageBody{ Body: fmt.Sprintf(message, a...), }, - ExplodingLifetime: explodingLifetime{duration}, + ExplodingLifetime: &ExplodingLifetime{duration}, } r, err := k.SendMessage(opts) @@ -267,7 +267,7 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du } // ReplyToChannel sends a chat message to a channel -func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.MessageID, message string, a ...interface{}) (SendResponse, error) { +func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo chat1.MessageID, message string, a ...interface{}) (SendResponse, error) { var r SendResponse opts := SendMessageOptions{ @@ -275,7 +275,7 @@ func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.Messa Message: SendMessageBody{ Body: fmt.Sprintf(message, a...), }, - ReplyTo: replyTo, + ReplyTo: &replyTo, } r, err := k.SendMessage(opts) @@ -287,7 +287,7 @@ func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.Messa } // ReplyToConvID sends a chat message to a conversation id -func (k *Keybase) ReplyToConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, message string, a ...interface{}) (SendResponse, error) { +func (k *Keybase) ReplyToConvID(convID chat1.ConvIDStr, replyTo chat1.MessageID, message string, a ...interface{}) (SendResponse, error) { var r SendResponse opts := SendMessageOptions{ @@ -295,7 +295,7 @@ func (k *Keybase) ReplyToConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID Message: SendMessageBody{ Body: fmt.Sprintf(message, a...), }, - ReplyTo: replyTo, + ReplyTo: &replyTo, } r, err := k.SendMessage(opts) diff --git a/types.go b/types.go index 5e53ba4..4b422e3 100644 --- a/types.go +++ b/types.go @@ -27,16 +27,16 @@ type Error struct { Message string `json:"message"` } -type explodingLifetime struct { +type ExplodingLifetime struct { time.Duration } -func (d *explodingLifetime) UnmarshalJSON(b []byte) (err error) { +func (d *ExplodingLifetime) UnmarshalJSON(b []byte) (err error) { d.Duration, err = time.ParseDuration(strings.Trim(string(b), `"`)) return } -func (d *explodingLifetime) MarshalJSON() (b []byte, err error) { +func (d *ExplodingLifetime) MarshalJSON() (b []byte, err error) { return []byte(fmt.Sprintf(`"%s"`, d.String())), nil } @@ -46,15 +46,15 @@ type SendMessageBody struct { // SendMessageOptions holds a set of options to be passed to SendMessage type SendMessageOptions struct { - Channel chat1.ChatChannel `json:"channel,omitempty"` - ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"` - Message SendMessageBody `json:",omitempty"` - Filename string `json:"filename,omitempty"` - Title string `json:"title,omitempty"` - MessageID chat1.MessageID `json:"message_id,omitempty"` - ConfirmLumenSend bool `json:"confirm_lumen_send"` - ReplyTo *chat1.MessageID `json:"reply_to,omitempty"` - ExplodingLifetime explodingLifetime `json:"exploding_lifetime,omitempty"` + Channel chat1.ChatChannel `json:"channel,omitempty"` + ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"` + Message SendMessageBody `json:",omitempty"` + Filename string `json:"filename,omitempty"` + Title string `json:"title,omitempty"` + MessageID chat1.MessageID `json:"message_id,omitempty"` + ConfirmLumenSend bool `json:"confirm_lumen_send"` + ReplyTo *chat1.MessageID `json:"reply_to,omitempty"` + ExplodingLifetime *ExplodingLifetime `json:"exploding_lifetime,omitempty"` } type sendMessageParams struct {