Browse Source

Add ReplyToChannel and ReplyToConvID, and attempt to fix ephemeral sends

main
Sam 4 years ago
parent
commit
3faadfd076
  1. 54
      chat.go
  2. 10
      types.go

54
chat.go

@ -235,10 +235,9 @@ func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration tim @@ -235,10 +235,9 @@ func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration tim
Message: SendMessageBody{
Body: fmt.Sprintf(message, a...),
},
ExplodingLifetime: explodingLifetime{duration},
}
opts.ExplodingLifetime.Duration = duration
r, err := k.SendMessage(opts)
if err != nil {
return r, err
@ -256,10 +255,9 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du @@ -256,10 +255,9 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du
Message: SendMessageBody{
Body: fmt.Sprintf(message, a...),
},
ExplodingLifetime: explodingLifetime{duration},
}
opts.ExplodingLifetime.Duration = duration
r, err := k.SendMessage(opts)
if err != nil {
return r, err
@ -268,43 +266,43 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du @@ -268,43 +266,43 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du
return r, nil
}
// Send sends a chat message
func (c Chat) Send(message ...string) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Params.Options = options{
Message: &mesg{},
}
// ReplyToChannel sends a chat message to a channel
func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.MessageID, message string, a ...interface{}) (SendResponse, error) {
var r SendResponse
m.Method = "send"
m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ")
opts := SendMessageOptions{
Channel: channel,
Message: SendMessageBody{
Body: fmt.Sprintf(message, a...),
},
ReplyTo: replyTo,
}
r, err := chatAPIOut(c.keybase, m)
r, err := k.SendMessage(opts)
if err != nil {
return r, err
}
return r, nil
}
// SendEphemeral sends an exploding chat message, with specified duration
func (c Chat) SendEphemeral(duration time.Duration, message ...string) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Params.Options = options{
Message: &mesg{},
// 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) {
var r SendResponse
opts := SendMessageOptions{
ConversationID: convID,
Message: SendMessageBody{
Body: fmt.Sprintf(message, a...),
},
ReplyTo: replyTo,
}
m.Params.Options.ExplodingLifetime.Duration = duration
m.Method = "send"
m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ")
r, err := chatAPIOut(c.keybase, m)
r, err := k.SendMessage(opts)
if err != nil {
return r, err
}
return r, nil
}

10
types.go

@ -27,16 +27,16 @@ type Error struct { @@ -27,16 +27,16 @@ type Error struct {
Message string `json:"message"`
}
type duration struct {
type explodingLifetime struct {
time.Duration
}
func (d *duration) 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 *duration) MarshalJSON() (b []byte, err error) {
func (d *explodingLifetime) MarshalJSON() (b []byte, err error) {
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
}
@ -54,7 +54,7 @@ type SendMessageOptions struct { @@ -54,7 +54,7 @@ type SendMessageOptions struct {
MessageID chat1.MessageID `json:"message_id,omitempty"`
ConfirmLumenSend bool `json:"confirm_lumen_send"`
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
ExplodingLifetime explodingLifetime `json:"exploding_lifetime,omitempty"`
}
type sendMessageParams struct {
@ -396,7 +396,7 @@ type options struct { @@ -396,7 +396,7 @@ type options struct {
GameID string `json:"game_id,omitempty"`
Alias string `json:"alias,omitempty"`
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
//ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
Name string `json:"name,omitempty"`
Public bool `json:"public,omitempty"`

Loading…
Cancel
Save