Browse Source

Ephemeral duration should be optional

main
Sam 4 years ago
parent
commit
26e487659c
  1. 12
      chat.go
  2. 24
      types.go

12
chat.go

@ -235,7 +235,7 @@ func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration tim
Message: SendMessageBody{ Message: SendMessageBody{
Body: fmt.Sprintf(message, a...), Body: fmt.Sprintf(message, a...),
}, },
ExplodingLifetime: explodingLifetime{duration}, ExplodingLifetime: &ExplodingLifetime{duration},
} }
r, err := k.SendMessage(opts) r, err := k.SendMessage(opts)
@ -255,7 +255,7 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du
Message: SendMessageBody{ Message: SendMessageBody{
Body: fmt.Sprintf(message, a...), Body: fmt.Sprintf(message, a...),
}, },
ExplodingLifetime: explodingLifetime{duration}, ExplodingLifetime: &ExplodingLifetime{duration},
} }
r, err := k.SendMessage(opts) 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 // 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 var r SendResponse
opts := SendMessageOptions{ opts := SendMessageOptions{
@ -275,7 +275,7 @@ func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.Messa
Message: SendMessageBody{ Message: SendMessageBody{
Body: fmt.Sprintf(message, a...), Body: fmt.Sprintf(message, a...),
}, },
ReplyTo: replyTo, ReplyTo: &replyTo,
} }
r, err := k.SendMessage(opts) 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 // 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 var r SendResponse
opts := SendMessageOptions{ opts := SendMessageOptions{
@ -295,7 +295,7 @@ func (k *Keybase) ReplyToConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID
Message: SendMessageBody{ Message: SendMessageBody{
Body: fmt.Sprintf(message, a...), Body: fmt.Sprintf(message, a...),
}, },
ReplyTo: replyTo, ReplyTo: &replyTo,
} }
r, err := k.SendMessage(opts) r, err := k.SendMessage(opts)

24
types.go

@ -27,16 +27,16 @@ type Error struct {
Message string `json:"message"` Message string `json:"message"`
} }
type explodingLifetime struct { type ExplodingLifetime struct {
time.Duration 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), `"`)) d.Duration, err = time.ParseDuration(strings.Trim(string(b), `"`))
return 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 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 // SendMessageOptions holds a set of options to be passed to SendMessage
type SendMessageOptions struct { type SendMessageOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"` Channel chat1.ChatChannel `json:"channel,omitempty"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"` ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
Message SendMessageBody `json:",omitempty"` Message SendMessageBody `json:",omitempty"`
Filename string `json:"filename,omitempty"` Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
MessageID chat1.MessageID `json:"message_id,omitempty"` MessageID chat1.MessageID `json:"message_id,omitempty"`
ConfirmLumenSend bool `json:"confirm_lumen_send"` ConfirmLumenSend bool `json:"confirm_lumen_send"`
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"` ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
ExplodingLifetime explodingLifetime `json:"exploding_lifetime,omitempty"` ExplodingLifetime *ExplodingLifetime `json:"exploding_lifetime,omitempty"`
} }
type sendMessageParams struct { type sendMessageParams struct {

Loading…
Cancel
Save