Skip to content

Commit bd88d7c

Browse files
nentenpizzademget
authored andcommitted
context: inherit thread on Notify
1 parent c6d60fc commit bd88d7c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

context.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ type Context interface {
9090
// In the case when no related data presented, returns an empty string.
9191
Text() string
9292

93+
// ThreadID returns the current message thread ID.
94+
ThreadID() int
95+
9396
// Entities returns the message entities, whether it's media caption's or the text's.
9497
// In the case when no entities presented, returns a nil.
9598
Entities() Entities
@@ -423,6 +426,15 @@ func (c *nativeContext) Args() []string {
423426
return nil
424427
}
425428

429+
func (c *nativeContext) ThreadID() int {
430+
switch {
431+
case c.Message() != nil:
432+
return c.Message().ThreadID
433+
default:
434+
return 0
435+
}
436+
}
437+
426438
func (c *nativeContext) Send(what interface{}, opts ...interface{}) error {
427439
opts = c.inheritOpts(opts...)
428440
_, err := c.b.Send(c.Recipient(), what, opts...)
@@ -450,8 +462,8 @@ func (c *nativeContext) inheritOpts(opts ...interface{}) []interface{} {
450462
}
451463

452464
switch {
453-
case !ignoreThread && c.Message() != nil && c.Message().ThreadID != 0:
454-
opts = append(opts, &Topic{ThreadID: c.Message().ThreadID})
465+
case !ignoreThread && c.ThreadID() != 0:
466+
opts = append(opts, &Topic{ThreadID: c.ThreadID()})
455467
}
456468

457469
return opts
@@ -551,7 +563,7 @@ func (c *nativeContext) DeleteAfter(d time.Duration) *time.Timer {
551563
}
552564

553565
func (c *nativeContext) Notify(action ChatAction) error {
554-
return c.b.Notify(c.Recipient(), action)
566+
return c.b.Notify(c.Recipient(), action, c.ThreadID())
555567
}
556568

557569
func (c *nativeContext) Ship(what ...interface{}) error {

0 commit comments

Comments
 (0)