Rewrite media caching (old image provider)
- Doesn't use pyotherside's image provider feature, for more flexibility and simplicity - Suitable for supporting matrix media events and more later - Avoid a lot of duplicate files that the old cache created due to server not returning what we expect, mistakes in Python/QML code, etc - Changed file structure (e.g. thumbnails/32x32/<mxc id> instead of thumbnails/<mxc id>.32.32.crop) - Backend.wait_until_account_exist: start issuing warnings if the function runs for more than 10s, which means in most case a bad user ID was passed - New HMxcImage QML component, used in H(User/Room)Avatar
This commit is contained in:
40
src/qml/Base/HMxcImage.qml
Normal file
40
src/qml/Base/HMxcImage.qml
Normal file
@@ -0,0 +1,40 @@
|
||||
import QtQuick 2.12
|
||||
import "../utils.js" as Utils
|
||||
|
||||
HImage {
|
||||
id: image
|
||||
source: sourceOverride || (show ? cachedPath : "")
|
||||
onMxcChanged: Qt.callLater(update)
|
||||
onWidthChanged: Qt.callLater(update)
|
||||
onHeightChanged: Qt.callLater(update)
|
||||
onVisibleChanged: Qt.callLater(update)
|
||||
|
||||
|
||||
property string clientUserId
|
||||
property string mxc
|
||||
property string sourceOverride: ""
|
||||
|
||||
property bool show: false
|
||||
property string cachedPath: ""
|
||||
|
||||
|
||||
function update() {
|
||||
let w = sourceSize.width || width
|
||||
let h = sourceSize.height || height
|
||||
|
||||
if (! image.mxc || w < 1 || h < 1 ) {
|
||||
show = false
|
||||
return
|
||||
}
|
||||
|
||||
let arg = [image.mxc, w, h]
|
||||
|
||||
if (! image) return // if it was destroyed
|
||||
|
||||
py.callClientCoro(clientUserId, "media_cache.thumbnail", arg, path => {
|
||||
if (! image) return
|
||||
image.cachedPath = path
|
||||
show = image.visible
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user