Skip to content

Commit

Permalink
context: fix thread inheriting
Browse files Browse the repository at this point in the history
  • Loading branch information
nentenpizza authored and demget committed Oct 14, 2024
1 parent 6985103 commit 4f8982b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (c *nativeContext) Args() []string {
}

func (c *nativeContext) Send(what interface{}, opts ...interface{}) error {
opts = c.inheritOpts(opts)
opts = c.inheritOpts(opts...)
_, err := c.b.Send(c.Recipient(), what, opts...)
return err
}
Expand All @@ -434,6 +434,10 @@ func (c *nativeContext) inheritOpts(opts ...interface{}) []interface{} {
ignoreThread bool
)

if opts == nil {
opts = make([]interface{}, 0)
}

for _, opt := range opts {
switch opt.(type) {
case Option:
Expand All @@ -447,14 +451,14 @@ func (c *nativeContext) inheritOpts(opts ...interface{}) []interface{} {

switch {
case !ignoreThread && c.Message() != nil && c.Message().ThreadID != 0:
opts = append(opts, Topic{ThreadID: c.Message().ThreadID})
opts = append(opts, &Topic{ThreadID: c.Message().ThreadID})
}

return opts
}

func (c *nativeContext) SendAlbum(a Album, opts ...interface{}) error {
opts = c.inheritOpts(opts)
opts = c.inheritOpts(opts...)

_, err := c.b.SendAlbum(c.Recipient(), a, opts...)
return err
Expand All @@ -465,7 +469,7 @@ func (c *nativeContext) Reply(what interface{}, opts ...interface{}) error {
if msg == nil {
return ErrBadContext
}
opts = c.inheritOpts(opts)
opts = c.inheritOpts(opts...)
_, err := c.b.Reply(msg, what, opts...)
return err
}
Expand All @@ -485,7 +489,7 @@ func (c *nativeContext) ForwardTo(to Recipient, opts ...interface{}) error {
}

func (c *nativeContext) Edit(what interface{}, opts ...interface{}) error {
opts = c.inheritOpts(opts)
opts = c.inheritOpts(opts...)

if c.u.InlineResult != nil {
_, err := c.b.Edit(c.u.InlineResult, what, opts...)
Expand All @@ -499,7 +503,7 @@ func (c *nativeContext) Edit(what interface{}, opts ...interface{}) error {
}

func (c *nativeContext) EditCaption(caption string, opts ...interface{}) error {
opts = c.inheritOpts(opts)
opts = c.inheritOpts(opts...)

if c.u.InlineResult != nil {
_, err := c.b.EditCaption(c.u.InlineResult, caption, opts...)
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func (b *Bot) extractOptions(how []interface{}) *SendOptions {
}
case *ReplyParams:
opts.ReplyParams = opt
case *Topic:
opts.ThreadID = opt.ThreadID
case Option:
switch opt {
case NoPreview:
Expand Down Expand Up @@ -152,8 +154,6 @@ func (b *Bot) extractOptions(how []interface{}) *SendOptions {
opts.ParseMode = opt
case Entities:
opts.Entities = opt
case Topic:
opts.ThreadID = opt.ThreadID
default:
panic("telebot: unsupported send-option")
}
Expand Down

0 comments on commit 4f8982b

Please sign in to comment.