Skip to content

Commit 9c03d02

Browse files
committed
fix(forwarder): non-video document clone, text only message forwarding
1 parent d077c11 commit 9c03d02

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

pkg/forwarder/forwarder.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,31 +199,30 @@ func (f *Forwarder) forwardMessage(ctx context.Context, elem Elem, grouped ...*t
199199
return nil, errors.Errorf("empty document %d", msg.ID)
200200
}
201201

202-
thumb, ok := tmedia.GetDocumentThumb(doc)
203-
if !ok {
204-
return nil, errors.Errorf("empty document thumb %d", msg.ID)
205-
}
206-
207-
thumbFile, err := f.cloneMedia(ctx, cloneOptions{
208-
elem: elem,
209-
media: thumb,
210-
progress: nopProgress{},
211-
}, elem.AsDryRun())
212-
if err != nil {
213-
return nil, errors.Wrap(err, "clone thumb")
214-
}
215-
216202
document := &tg.InputMediaUploadedDocument{
217203
NosoundVideo: false, // do not set
218204
ForceFile: false, // do not set
219205
Spoiler: m.Spoiler,
220206
File: mediaFile,
221-
Thumb: thumbFile,
222207
MimeType: doc.MimeType,
223208
Attributes: doc.Attributes,
224209
Stickers: nil, // do not set
225-
TTLSeconds: m.TTLSeconds,
210+
TTLSeconds: 0, // do not set
211+
}
212+
213+
if thumb, ok := tmedia.GetDocumentThumb(doc); ok {
214+
thumbFile, err := f.cloneMedia(ctx, cloneOptions{
215+
elem: elem,
216+
media: thumb,
217+
progress: nopProgress{},
218+
}, elem.AsDryRun())
219+
if err != nil {
220+
return nil, errors.Wrap(err, "clone thumb")
221+
}
222+
223+
document.Thumb = thumbFile
226224
}
225+
227226
document.SetFlags()
228227

229228
inputMedia = document
@@ -420,22 +419,23 @@ func photoOrDocument(media tg.MessageMediaClass) bool {
420419
}
421420

422421
func mediaSizeSum(msg *tg.Message, grouped ...*tg.Message) (int64, error) {
423-
m, ok := tmedia.GetMedia(msg)
424-
if !ok {
425-
return 0, errors.Errorf("can't get media from message")
426-
}
427-
total := m.Size
428-
429422
if len(grouped) > 0 {
430-
total = 0
423+
total := int64(0)
431424
for _, gm := range grouped {
432425
m, ok := tmedia.GetMedia(gm)
433426
if !ok {
434-
return 0, errors.Errorf("can't get media from message")
427+
return 0, errors.Errorf("can't get media from message %d", gm.ID)
435428
}
436429
total += m.Size
437430
}
431+
432+
return total, nil
433+
}
434+
435+
m, ok := tmedia.GetMedia(msg)
436+
if !ok { // maybe it's a text only message
437+
return 0, nil
438438
}
439439

440-
return total, nil
440+
return m.Size, nil
441441
}

0 commit comments

Comments
 (0)