mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-23 21:11:55 +00:00
5953031bfc
YouTube link unfurling was not working for a couple reasons. There were two main parts fixed: 1. QML context for messages pertaining to linkUrls and imageUrls was changed from implicit to explicit. By this, I mean that any time we referenced linkUrls/imageUrls, we were relying on the knowledge that those values would be populated by some parent context several levels up. Now, we are referring to properties that have been explicitly defined on the components. This offers the ability to reuse components, and makes reading the code and debugging much easier. 2. Error handling has been added to getting link preview data. An unhandled "error" was thrown each time a link that wasn't whitelisted was passed in, causing the app to crash. For example, when a link to a tenor gif was posted in the chat, that URL was not whitelisted, causing the app to crash.
117 lines
3.9 KiB
QML
117 lines
3.9 KiB
QML
import QtQuick 2.3
|
|
import QtGraphicalEffects 1.13
|
|
import "../../../../../shared"
|
|
import "../../../../../imports"
|
|
|
|
Item {
|
|
property int verticalPadding: 0
|
|
property int imageWidth: 350
|
|
property bool isCurrentUser: false
|
|
property url source
|
|
property bool playing: true
|
|
property bool isAnimated: !!source && source.toString().endsWith('.gif')
|
|
signal clicked(var image)
|
|
property var container
|
|
|
|
id: imageContainer
|
|
width: loadingImage.visible ? loadingImage.width : imageMessage.width
|
|
height: loadingImage.visible ? loadingImage.height : imageMessage.paintedHeight
|
|
|
|
Rectangle {
|
|
id: loadingImage
|
|
property bool hasError: false
|
|
width: hasError ? 200 : imageContainer.imageWidth
|
|
height: hasError ? 75 : imageContainer.imageWidth
|
|
border.width: 1
|
|
border.color: Style.current.border
|
|
radius: Style.current.radius
|
|
|
|
StyledText {
|
|
//% "Error loading the image"
|
|
//% "Loading image..."
|
|
text: loadingImage.hasError ? qsTrId("error-loading-the-image") : qsTrId("loading-image---")
|
|
color: loadingImage.hasError ? Style.current.red : Style.current.textColor
|
|
font.pixelSize: 15
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: applicationWindow
|
|
onActiveChanged: {
|
|
if (applicationWindow.active === false) {
|
|
imageMessage.playing = false
|
|
} else {
|
|
imageMessage.playing = Qt.binding(function () {return imageContainer.playing})
|
|
}
|
|
}
|
|
}
|
|
|
|
AnimatedImage {
|
|
id: imageMessage
|
|
width: sourceSize.width > imageWidth ? imageWidth : sourceSize.width
|
|
fillMode: Image.PreserveAspectFit
|
|
source: imageContainer.source
|
|
playing: imageContainer.playing
|
|
onStatusChanged: {
|
|
if (imageMessage.status === Image.Error) {
|
|
loadingImage.hasError = true
|
|
imageMessage.height = 0
|
|
imageMessage.source = ""
|
|
imageMessage.visible = false
|
|
} else if (imageMessage.status === Image.Ready) {
|
|
loadingImage.visible = false
|
|
scrollToBottom(true, root.container)
|
|
}
|
|
}
|
|
|
|
layer.enabled: true
|
|
layer.effect: OpacityMask {
|
|
maskSource: Item {
|
|
width: imageMessage.width
|
|
height: imageMessage.height
|
|
|
|
Rectangle {
|
|
anchors.top: parent.top
|
|
anchors.left: parent.left
|
|
width: imageMessage.width
|
|
height: imageMessage.height
|
|
radius: 16
|
|
}
|
|
|
|
Rectangle {
|
|
anchors.bottom: parent.bottom
|
|
anchors.left: parent.left
|
|
width: 32
|
|
height: 32
|
|
radius: 4
|
|
visible: !imageContainer.isCurrentUser
|
|
}
|
|
Rectangle {
|
|
anchors.bottom: parent.bottom
|
|
anchors.right: parent.right
|
|
width: 32
|
|
height: 32
|
|
radius: 4
|
|
visible: imageContainer.isCurrentUser
|
|
}
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
cursorShape: Qt.PointingHandCursor
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
if (imageContainer.isAnimated) {
|
|
// FIXME the ListView completely removes Items that scroll out of view
|
|
// so when we scroll backto the image, it gets reloaded and playing is reset
|
|
imageContainer.playing = !imageContainer.playing
|
|
return
|
|
}
|
|
imageContainer.clicked(imageMessage)
|
|
}
|
|
}
|
|
}
|
|
}
|