Fix image events opened/copied url

This commit is contained in:
miruka 2019-11-04 10:46:06 -04:00
parent ca09effd6e
commit de8d0b5823
3 changed files with 21 additions and 6 deletions

View File

@ -138,6 +138,11 @@ class Backend:
return hsluv.hsluv_to_rgb([hue, saturation, lightness]) return hsluv.hsluv_to_rgb([hue, saturation, lightness])
@staticmethod
async def mxc_to_http(mxc: str) -> Optional[str]:
return nio.Api.mxc_to_http(mxc)
@staticmethod @staticmethod
async def check_exported_keys_passphrase(file_path: str, passphrase: str, async def check_exported_keys_passphrase(file_path: str, passphrase: str,
) -> Union[bool, Tuple[str, bool]]: ) -> Union[bool, Tuple[str, bool]]:

View File

@ -3,10 +3,18 @@ import QtQuick 2.12
HImage { HImage {
id: image id: image
source: sourceOverride || (show ? cachedPath : "") source: sourceOverride || (show ? cachedPath : "")
onMxcChanged: Qt.callLater(update)
onWidthChanged: Qt.callLater(update) onWidthChanged: Qt.callLater(update)
onHeightChanged: Qt.callLater(update) onHeightChanged: Qt.callLater(update)
onVisibleChanged: Qt.callLater(update) onVisibleChanged: Qt.callLater(update)
onMxcChanged: {
Qt.callLater(update)
if (mxc.startsWith("mxc://")) {
py.callCoro("mxc_to_http", [mxc], http => { httpUrl = http || "" })
} else {
httpUrl = mxc
}
}
property string clientUserId property string clientUserId
@ -16,6 +24,7 @@ HImage {
property bool show: false property bool show: false
property string cachedPath: "" property string cachedPath: ""
property string httpUrl: ""
function update() { function update() {

View File

@ -11,23 +11,24 @@ HMxcImage {
Utils.urlExtension(loader.mediaUrl) === "gif" Utils.urlExtension(loader.mediaUrl) === "gif"
clientUserId: chatPage.userId clientUserId: chatPage.userId
thumbnail: ! animated thumbnail: ! animated
mxc: thumbnail ? (loader.thumbnailMxc || loader.mediaUrl) : openUrl mxc: thumbnail ?
(loader.thumbnailMxc || loader.mediaUrl) :
(loader.mediaUrl || loader.thumbnailMxc)
property EventMediaLoader loader property EventMediaLoader loader
readonly property url openUrl: loader.mediaUrl || loader.thumbnailMxc
TapHandler { TapHandler {
onTapped: if (! image.animated) Qt.openUrlExternally(openUrl) onTapped: if (! image.animated) Qt.openUrlExternally(image.httpUrl)
onDoubleTapped: Qt.openUrlExternally(openUrl) onDoubleTapped: Qt.openUrlExternally(image.httpUrl)
} }
HoverHandler { HoverHandler {
id: hover id: hover
onHoveredChanged: onHoveredChanged:
eventDelegate.hoveredMediaTypeUrl = eventDelegate.hoveredMediaTypeUrl =
hovered ? [EventDelegate.Media.Image, openUrl] : [] hovered ? [EventDelegate.Media.Image, image.httpUrl] : []
} }
EventImageTextBubble { EventImageTextBubble {