From 25ce08891d3119cf6d68471780ab07ba9e898030 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 16 Nov 2019 08:06:56 -0400 Subject: [PATCH] Fix which EventImage url gets opened/copied --- src/qml/Base/HMxcImage.qml | 13 +---------- src/qml/Chat/Timeline/EventImage.qml | 32 ++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/qml/Base/HMxcImage.qml b/src/qml/Base/HMxcImage.qml index 1bf7f558..1e78bd3a 100644 --- a/src/qml/Base/HMxcImage.qml +++ b/src/qml/Base/HMxcImage.qml @@ -7,17 +7,7 @@ HImage { onWidthChanged: Qt.callLater(update) onHeightChanged: Qt.callLater(update) onVisibleChanged: Qt.callLater(update) - onMxcChanged: { - Qt.callLater(update) - - if (isMxc) { - py.callCoro("mxc_to_http", [mxc], http => { - image.httpUrl = http || "" - }) - } else { - httpUrl = mxc - } - } + onMxcChanged: Qt.callLater(update) property string mxc @@ -27,7 +17,6 @@ HImage { property bool show: false property string cachedPath: "" - property string httpUrl: "" readonly property bool isMxc: mxc.startsWith("mxc://") diff --git a/src/qml/Chat/Timeline/EventImage.qml b/src/qml/Chat/Timeline/EventImage.qml index bc120ead..a563059c 100644 --- a/src/qml/Chat/Timeline/EventImage.qml +++ b/src/qml/Chat/Timeline/EventImage.qml @@ -21,7 +21,6 @@ HMxcImage { property EventMediaLoader loader readonly property bool isEncrypted: ! Utils.isEmptyObject(cryptDict) - readonly property string openUrl: isEncrypted ? cachedPath : image.httpUrl readonly property real maxHeight: theme.chat.message.thumbnailMaxHeightRatio @@ -48,16 +47,37 @@ HMxcImage { ) + function getOpenUrl(callback) { + if (image.isEncrypted) { + callback(image.cachedPath) + return + } + + let toOpen = loader.mediaUrl || loader.thumbnailMxc + let isMxc = toOpen.startsWith("mxc://") + + isMxc ? + py.callCoro("mxc_to_http", [toOpen], callback) : callback(toOpen) + } + + TapHandler { - onTapped: if (! image.animated) Qt.openUrlExternally(openUrl) - onDoubleTapped: Qt.openUrlExternally(openUrl) + onTapped: if (! image.animated) getOpenUrl(Qt.openUrlExternally) + onDoubleTapped: getOpenUrl(Qt.openUrlExternally) } HoverHandler { id: hover - onHoveredChanged: - eventDelegate.hoveredMediaTypeUrl = - hovered ? [EventDelegate.Media.Image, openUrl] : [] + onHoveredChanged: { + if (hovered) { + getOpenUrl(url => { + eventDelegate.hoveredMediaTypeUrl = + [EventDelegate.Media.Image, url] + }) + } else { + eventDelegate.hoveredMediaTypeUrl = [] + } + } } EventImageTextBubble {