2019-09-14 00:36:19 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import "../../Base"
|
|
|
|
import "../../utils.js" as Utils
|
|
|
|
|
|
|
|
HLoader {
|
|
|
|
id: loader
|
2019-09-14 17:48:53 -04:00
|
|
|
x: eventContent.spacing
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
onTypeChanged: {
|
|
|
|
if (type === EventDelegate.Media.Image) {
|
|
|
|
var file = "EventImage.qml"
|
|
|
|
|
2019-12-16 18:19:06 -04:00
|
|
|
} else if (type !== EventDelegate.Media.Page) {
|
2019-12-16 17:48:07 -04:00
|
|
|
var file = "EventFile.qml"
|
|
|
|
|
|
|
|
} else { return }
|
|
|
|
|
|
|
|
loader.setSource(file, {loader})
|
|
|
|
}
|
|
|
|
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-10-30 06:47:59 -04:00
|
|
|
property QtObject singleMediaInfo
|
2019-11-04 07:00:28 -04:00
|
|
|
property string mediaUrl
|
2019-10-30 09:21:58 -04:00
|
|
|
property string showSender: ""
|
|
|
|
property string showDate: ""
|
2019-11-06 09:48:27 -04:00
|
|
|
property string showLocalEcho: ""
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 18:05:09 -04:00
|
|
|
property string downloadedPath: ""
|
2019-12-16 17:48:07 -04:00
|
|
|
|
2019-09-14 00:36:19 -04:00
|
|
|
readonly property var imageExtensions: [
|
|
|
|
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
|
|
|
"tiff", "webp", "svg",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var videoExtensions: [
|
|
|
|
"3gp", "avi", "flv", "m4p", "m4v", "mkv", "mov", "mp4",
|
|
|
|
"mpeg", "mpg", "ogv", "qt", "vob", "webm", "wmv", "yuv",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var audioExtensions: [
|
|
|
|
"pcm", "wav", "raw", "aiff", "flac", "m4a", "tta", "aac", "mp3",
|
|
|
|
"ogg", "oga", "opus",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property int type: {
|
2019-12-09 11:35:50 -04:00
|
|
|
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
2019-11-27 06:18:06 -04:00
|
|
|
return EventDelegate.Media.Image
|
|
|
|
|
2019-11-11 05:26:32 -04:00
|
|
|
let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-11-11 05:26:32 -04:00
|
|
|
if (mainType === "image") return EventDelegate.Media.Image
|
|
|
|
if (mainType === "video") return EventDelegate.Media.Video
|
|
|
|
if (mainType === "audio") return EventDelegate.Media.Audio
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-11-11 05:26:32 -04:00
|
|
|
let fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
|
|
|
|
|
|
|
if (fileEvents.includes(singleMediaInfo.event_type))
|
2019-09-14 18:33:32 -04:00
|
|
|
return EventDelegate.Media.File
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-10-30 06:47:59 -04:00
|
|
|
// If this is a preview for a link in a normal message
|
2019-09-14 00:36:19 -04:00
|
|
|
let ext = Utils.urlExtension(mediaUrl)
|
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
|
|
|
|
if (videoExtensions.includes(ext)) return EventDelegate.Media.Video
|
|
|
|
if (audioExtensions.includes(ext)) return EventDelegate.Media.Audio
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
return EventDelegate.Media.Page
|
2019-09-14 00:36:19 -04:00
|
|
|
}
|
|
|
|
|
2019-11-04 07:00:28 -04:00
|
|
|
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
|
2019-09-14 00:36:19 -04:00
|
|
|
|
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
function download(callback) {
|
2019-12-16 18:19:06 -04:00
|
|
|
if (! loader.mediaUrl.startsWith("mxc://")) {
|
|
|
|
downloadedPath = loader.mediaUrl
|
|
|
|
callback(loader.mediaUrl)
|
|
|
|
}
|
|
|
|
|
2019-12-16 18:05:09 -04:00
|
|
|
if (! downloadedPath) print("Downloading " + loader.mediaUrl + " ...")
|
2019-09-17 23:23:47 -04:00
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict]
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
py.callCoro("media_cache.get_media", args, path => {
|
2019-12-16 18:05:09 -04:00
|
|
|
if (! downloadedPath) print("Done: " + path)
|
|
|
|
downloadedPath = path
|
2019-12-16 17:48:07 -04:00
|
|
|
callback(path)
|
|
|
|
})
|
2019-09-14 00:36:19 -04:00
|
|
|
}
|
|
|
|
}
|