forked from MirrorHub/mautrix-whatsapp
Pass through media dimensions from WhatsApp
This commit is contained in:
parent
b8a8dcffaf
commit
be05d7d4a9
1 changed files with 12 additions and 2 deletions
14
portal.go
14
portal.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue