tomatrix: fix default file names

This commit is contained in:
Tulir Asokan
2026-04-13 16:47:47 +03:00
parent 8b3707b0ee
commit 95db7a6d0d
+10 -2
View File
@@ -517,6 +517,7 @@ func (tc *TelegramClient) convertMediaRequiringUpload(
} }
if video, ok := msgMedia.Video.(*tg.Document); ok { if video, ok := msgMedia.Video.(*tg.Document); ok {
content.MsgType = event.MsgVideo content.MsgType = event.MsgVideo
content.Body = strings.Replace(content.Body, "image", "live_photo", 1)
telegramMediaID = video.GetID() telegramMediaID = video.GetID()
mediaTransferer = transferer.WithLivePhoto(photo, video) mediaTransferer = transferer.WithLivePhoto(photo, video)
extraInfo["fi.mau.telegram.live_photo"] = true extraInfo["fi.mau.telegram.live_photo"] = true
@@ -564,6 +565,7 @@ func (tc *TelegramClient) convertMediaRequiringUpload(
telegramMediaID = document.GetID() telegramMediaID = document.GetID()
content.MsgType = event.MsgFile content.MsgType = event.MsgFile
defaultFileName := "file_document"
for _, attr := range document.GetAttributes() { for _, attr := range document.GetAttributes() {
switch a := attr.(type) { switch a := attr.(type) {
@@ -574,6 +576,7 @@ func (tc *TelegramClient) convertMediaRequiringUpload(
content.FileName = a.GetFileName() content.FileName = a.GetFileName()
} }
case *tg.DocumentAttributeVideo: case *tg.DocumentAttributeVideo:
defaultFileName = "video_document"
isVideo = true isVideo = true
content.MsgType = event.MsgVideo content.MsgType = event.MsgVideo
transferer = transferer.WithVideo(a) transferer = transferer.WithVideo(a)
@@ -596,13 +599,17 @@ func (tc *TelegramClient) convertMediaRequiringUpload(
} }
} }
if a.Voice { if a.Voice {
defaultFileName = "Voice message"
content.MSC3245Voice = &event.MSC3245Voice{} content.MSC3245Voice = &event.MSC3245Voice{}
} else {
defaultFileName = "audio_document"
} }
case *tg.DocumentAttributeImageSize: case *tg.DocumentAttributeImageSize:
transferer = transferer.WithImageSize(a) transferer = transferer.WithImageSize(a)
if content.MsgType == event.MsgFile { if content.MsgType == event.MsgFile {
content.MsgType = event.MsgImage content.MsgType = event.MsgImage
extra["fi.mau.telegram.force_document"] = true extra["fi.mau.telegram.force_document"] = true
defaultFileName = "image_document"
} }
case *tg.DocumentAttributeSticker: case *tg.DocumentAttributeSticker:
isSticker = true isSticker = true
@@ -629,14 +636,15 @@ func (tc *TelegramClient) convertMediaRequiringUpload(
case *tg.DocumentAttributeAnimated: case *tg.DocumentAttributeAnimated:
isVideoGif = true isVideoGif = true
extraInfo["fi.mau.telegram.gif"] = true extraInfo["fi.mau.telegram.gif"] = true
defaultFileName = "gif"
} }
} }
if content.FileName == "" { if content.FileName == "" && content.Body == "" {
if content.Body != "" { if content.Body != "" {
content.FileName = content.Body content.FileName = content.Body
} else { } else {
content.Body = "document" content.Body = defaultFileName
} }
} }