2019-11-04 04:48:12 +11:00
|
|
|
import QtQuick 2.12
|
|
|
|
|
|
|
|
HImage {
|
|
|
|
id: image
|
|
|
|
source: sourceOverride || (show ? cachedPath : "")
|
|
|
|
onWidthChanged: Qt.callLater(update)
|
|
|
|
onHeightChanged: Qt.callLater(update)
|
|
|
|
onVisibleChanged: Qt.callLater(update)
|
2019-11-05 01:46:06 +11:00
|
|
|
onMxcChanged: {
|
|
|
|
Qt.callLater(update)
|
|
|
|
|
|
|
|
if (mxc.startsWith("mxc://")) {
|
2019-11-05 05:55:26 +11:00
|
|
|
py.callCoro("mxc_to_http", [mxc], http => {
|
|
|
|
image.httpUrl = http || ""
|
|
|
|
})
|
2019-11-05 01:46:06 +11:00
|
|
|
} else {
|
|
|
|
httpUrl = mxc
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
property string clientUserId
|
|
|
|
property string mxc
|
|
|
|
property string sourceOverride: ""
|
2019-11-05 01:29:41 +11:00
|
|
|
property bool thumbnail: true
|
2019-11-05 05:37:25 +11:00
|
|
|
property var cryptDict: ({})
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
property bool show: false
|
|
|
|
property string cachedPath: ""
|
2019-11-05 01:46:06 +11:00
|
|
|
property string httpUrl: ""
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
let w = sourceSize.width || width
|
|
|
|
let h = sourceSize.height || height
|
|
|
|
|
|
|
|
if (! image.mxc || w < 1 || h < 1 ) {
|
|
|
|
show = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! image) return // if it was destroyed
|
|
|
|
|
2019-11-04 22:00:28 +11:00
|
|
|
if (! image.mxc.startsWith("mxc://")) {
|
2019-11-06 00:19:48 +11:00
|
|
|
if (source != mxc) source = mxc
|
|
|
|
show = image.visible
|
2019-11-04 22:00:28 +11:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-05 01:29:41 +11:00
|
|
|
let method = image.thumbnail ? "get_thumbnail" : "get_media"
|
2019-11-05 05:37:25 +11:00
|
|
|
let args = image.thumbnail ?
|
|
|
|
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
2019-11-05 01:29:41 +11:00
|
|
|
|
2019-11-04 22:00:28 +11:00
|
|
|
py.callClientCoro(
|
2019-11-05 01:29:41 +11:00
|
|
|
clientUserId, "media_cache." + method, args, path => {
|
2019-11-04 22:00:28 +11:00
|
|
|
if (! image) return
|
2019-11-06 00:19:48 +11:00
|
|
|
if (image.cachedPath != path) image.cachedPath = path
|
|
|
|
show = image.visible
|
2019-11-04 22:00:28 +11:00
|
|
|
}
|
|
|
|
)
|
2019-11-04 04:48:12 +11:00
|
|
|
}
|
|
|
|
}
|