Pass through media dimensions from WhatsApp

This commit is contained in:
Tulir Asokan 2021-12-09 19:20:52 +02:00
parent b8a8dcffaf
commit be05d7d4a9

View file

@ -1553,7 +1553,6 @@ type MediaMessage interface {
type MediaMessageWithThumbnail interface {
MediaMessage
GetJpegThumbnail() []byte
GetCaption() string
}
type MediaMessageWithCaption interface {
@ -1561,6 +1560,12 @@ type MediaMessageWithCaption interface {
GetCaption() string
}
type MediaMessageWithDimensions interface {
MediaMessage
GetHeight() uint32
GetWidth() uint32
}
type MediaMessageWithFileName interface {
MediaMessage
GetFileName() string
@ -1602,7 +1607,12 @@ func (portal *Portal) convertMediaMessage(intent *appservice.IntentAPI, source *
}
var width, height int
if strings.HasPrefix(msg.GetMimetype(), "image/") {
messageWithDimensions, ok := msg.(MediaMessageWithDimensions)
if ok {
width = int(messageWithDimensions.GetWidth())
height = int(messageWithDimensions.GetHeight())
}
if width == 0 && height == 0 && strings.HasPrefix(msg.GetMimetype(), "image/") {
cfg, _, _ := image.DecodeConfig(bytes.NewReader(data))
width, height = cfg.Width, cfg.Height
}