(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -129,7 +129,19 @@ type Draft struct {
|
||||
//
|
||||
// The caller must set a chat with SetChat before Push or Flush.
|
||||
func (p *DraftProvider) NewDraft(parseMode tgapi.ParseMode) *Draft {
|
||||
id := p.generator.Next()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
var id uint64
|
||||
for {
|
||||
id = p.generator.Next()
|
||||
if id == 0 {
|
||||
continue
|
||||
}
|
||||
if _, exists := p.drafts[id]; !exists {
|
||||
break
|
||||
}
|
||||
}
|
||||
draft := &Draft{
|
||||
api: p.api,
|
||||
provider: p,
|
||||
@@ -137,9 +149,7 @@ func (p *DraftProvider) NewDraft(parseMode tgapi.ParseMode) *Draft {
|
||||
ID: id,
|
||||
Message: "",
|
||||
}
|
||||
p.mu.Lock()
|
||||
p.drafts[id] = draft
|
||||
p.mu.Unlock()
|
||||
return draft
|
||||
}
|
||||
|
||||
@@ -154,10 +164,9 @@ func (d *Draft) SetChat(chatID int64, messageThreadID int) *Draft {
|
||||
|
||||
// SetEntities replaces the draft's message entities.
|
||||
//
|
||||
// Entities are stored by reference. If you plan to mutate the slice later,
|
||||
// pass a copy: `SetEntities(append([]tgapi.MessageEntity{}, myEntities...))`.
|
||||
// The entities slice is copied.
|
||||
func (d *Draft) SetEntities(entities []tgapi.MessageEntity) *Draft {
|
||||
d.entities = entities
|
||||
d.entities = append([]tgapi.MessageEntity(nil), entities...)
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -220,6 +229,9 @@ func (d *Draft) Flush() error {
|
||||
if err := validateMessageText(d.Message); err != nil {
|
||||
return err
|
||||
}
|
||||
if d.api == nil {
|
||||
return ErrAPIIsNil
|
||||
}
|
||||
|
||||
params := tgapi.SendMessage{
|
||||
ChatID: d.chatID,
|
||||
@@ -252,6 +264,9 @@ func (d *Draft) push(text string) error {
|
||||
return err
|
||||
}
|
||||
d.Message = candidate
|
||||
if d.api == nil {
|
||||
return ErrAPIIsNil
|
||||
}
|
||||
params := tgapi.SendMessageDraft{
|
||||
ChatID: d.chatID,
|
||||
DraftID: d.ID,
|
||||
|
||||
Reference in New Issue
Block a user