From 741ad786020f2f9c22f89000f0f6b9cf925e3da4 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Thu, 21 Jan 2021 23:33:54 +0100 Subject: [PATCH] Sometimes images don't come with a proper width/height --- qml/components/messageContent/MessagePhoto.qml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qml/components/messageContent/MessagePhoto.qml b/qml/components/messageContent/MessagePhoto.qml index 8c30e6f..beb2381 100644 --- a/qml/components/messageContent/MessagePhoto.qml +++ b/qml/components/messageContent/MessagePhoto.qml @@ -21,9 +21,23 @@ import Sailfish.Silica 1.0 import "../" MessageContentBase { + + function calculateBiggest() { + var candidateBiggest = rawMessage.content.photo.sizes[rawMessage.content.photo.sizes.length - 1]; + if (candidateBiggest.width === 0 && rawMessage.content.photo.sizes.length > 1) { + for (var i = (rawMessage.content.photo.sizes.length - 2); i >= 0; i--) { + candidateBiggest = rawMessage.content.photo.sizes[i]; + if (candidateBiggest.width > 0) { + break; + } + } + } + return candidateBiggest; + } + height: Math.max(Theme.itemSizeExtraSmall, Math.min(defaultHeight, width / (biggest.width/biggest.height))) readonly property int defaultHeight: Math.round(width * 0.66666666) - readonly property var biggest: rawMessage.content.photo.sizes[rawMessage.content.photo.sizes.length - 1]; + readonly property var biggest: calculateBiggest(); onClicked: { pageStack.push(Qt.resolvedUrl("../../pages/ImagePage.qml"), {