From 6eacf38d7487300614f93e0ab6b0c292d825e503 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 23 Apr 2026 14:51:33 +0300 Subject: [PATCH] tomatrix: use extra field in info for custom fields --- pkg/connector/media/transfer.go | 5 +++++ pkg/connector/tomatrix.go | 20 +++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/connector/media/transfer.go b/pkg/connector/media/transfer.go index 94027f56..4e8d9708 100644 --- a/pkg/connector/media/transfer.go +++ b/pkg/connector/media/transfer.go @@ -197,6 +197,11 @@ func (t *Transferer) WithVideo(attr *tg.DocumentAttributeVideo) *Transferer { return t } +func (t *Transferer) WithAudio(attr *tg.DocumentAttributeAudio) *Transferer { + t.fileInfo.Duration = attr.Duration * 1000 + return t +} + func (t *Transferer) WithImageSize(attr *tg.DocumentAttributeImageSize) *Transferer { t.fileInfo.Width, t.fileInfo.Height = attr.W, attr.H t.adjustStickerSize() diff --git a/pkg/connector/tomatrix.go b/pkg/connector/tomatrix.go index 688a20cd..4566370b 100644 --- a/pkg/connector/tomatrix.go +++ b/pkg/connector/tomatrix.go @@ -584,11 +584,10 @@ func (tc *TelegramClient) convertMediaRequiringUpload( if a.RoundMessage { extraInfo["fi.mau.telegram.round_message"] = a.RoundMessage } - extraInfo["duration"] = int(a.Duration * 1000) case *tg.DocumentAttributeAudio: if content.MsgType != event.MsgVideo { content.MsgType = event.MsgAudio - extraInfo["duration"] = int(a.Duration * 1000) // only set the duration is not already set by the video handling logic + transferer = transferer.WithAudio(a) // only set the duration is not already set by the video handling logic } content.MSC1767Audio = &event.MSC1767Audio{ Duration: a.Duration * 1000, @@ -663,14 +662,6 @@ func (tc *TelegramClient) convertMediaRequiringUpload( } } - if isVideoGif { - extraInfo["fi.mau.gif"] = true - extraInfo["fi.mau.loop"] = true - extraInfo["fi.mau.autoplay"] = true - extraInfo["fi.mau.hide_controls"] = true - extraInfo["fi.mau.no_audio"] = true - } - if _, ok := document.GetThumbs(); ok && eventType != event.EventSticker { var thumbnailURL id.ContentURIString var thumbnailFile *event.EncryptedFileInfo @@ -752,6 +743,13 @@ func (tc *TelegramClient) convertMediaRequiringUpload( content.FileName = content.FileName + exmime.ExtensionFromMimetype(content.Info.MimeType) } } + if isVideoGif { + content.Info.MauGIF = true + extraInfo["fi.mau.loop"] = true + extraInfo["fi.mau.autoplay"] = true + extraInfo["fi.mau.hide_controls"] = true + extraInfo["fi.mau.no_audio"] = true + } // Handle spoilers // See: https://github.com/matrix-org/matrix-spec-proposals/pull/3725 @@ -763,7 +761,7 @@ func (tc *TelegramClient) convertMediaRequiringUpload( extraInfo["fi.mau.telegram.spoiler"] = true } if len(extraInfo) > 0 { - extra["info"] = extraInfo + content.Info.Extra = extraInfo } converted = &bridgev2.ConvertedMessagePart{