diff --git a/imports/NeoChat/Component/Timeline/FileDelegate.qml b/imports/NeoChat/Component/Timeline/FileDelegate.qml index d98834794..5251d439f 100644 --- a/imports/NeoChat/Component/Timeline/FileDelegate.qml +++ b/imports/NeoChat/Component/Timeline/FileDelegate.qml @@ -21,9 +21,20 @@ TimelineContainer { onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions + readonly property bool downloaded: progressInfo && progressInfo.completed + + function saveFileAs() { + const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay) + dialog.open() + dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId) + } + + function openSavedFile() { + if (Qt.openUrlExternally(progressInfo.localPath)) return; + if (Qt.openUrlExternally(progressInfo.localDir)) return; + } + innerObject: RowLayout { - property bool openOnFinished: false - readonly property bool downloaded: progressInfo && progressInfo.completed Layout.fillWidth: true Layout.maximumWidth: fileDelegate.bubbleMaxWidth @@ -129,16 +140,5 @@ TimelineContainer { acceptedButtons: Qt.LeftButton onLongPressed: openFileContext(model, parent) } - - function saveFileAs() { - var dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay) - dialog.open() - dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId) - } - - function openSavedFile() { - if (Qt.openUrlExternally(progressInfo.localPath)) return; - if (Qt.openUrlExternally(progressInfo.localDir)) return; - } } } diff --git a/imports/NeoChat/Component/Timeline/ImageDelegate.qml b/imports/NeoChat/Component/Timeline/ImageDelegate.qml index 95bbf177d..66c047555 100644 --- a/imports/NeoChat/Component/Timeline/ImageDelegate.qml +++ b/imports/NeoChat/Component/Timeline/ImageDelegate.qml @@ -21,19 +21,20 @@ TimelineContainer { onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions + property var content: model.content + readonly property bool isAnimated: contentType === "image/gif" + + property bool openOnFinished: false + readonly property bool downloaded: progressInfo && progressInfo.completed + + readonly property bool isThumbnail: !(content.info.thumbnail_info == null || content.thumbnailMediaId == null) + // readonly property var info: isThumbnail ? content.info.thumbnail_info : content.info + readonly property var info: content.info + readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId + innerObject: Image { id: img - property var content: model.content - readonly property bool isAnimated: contentType === "image/gif" - - property bool openOnFinished: false - readonly property bool downloaded: progressInfo && progressInfo.completed - - readonly property bool isThumbnail: !(content.info.thumbnail_info == null || content.thumbnailMediaId == null) - // readonly property var info: isThumbnail ? content.info.thumbnail_info : content.info - readonly property var info: content.info - readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId Layout.maximumWidth: imageDelegate.bubbleMaxWidth source: "image://mxc/" + mediaId @@ -108,18 +109,16 @@ TimelineContainer { } } - function downloadAndOpen() - { - if (downloaded) openSavedFile() - else - { + function downloadAndOpen() { + if (downloaded) { + openSavedFile() + } else { openOnFinished = true currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) } } - function openSavedFile() - { + function openSavedFile() { if (Qt.openUrlExternally(progressInfo.localPath)) return; if (Qt.openUrlExternally(progressInfo.localDir)) return; } diff --git a/imports/NeoChat/Component/Timeline/VideoDelegate.qml b/imports/NeoChat/Component/Timeline/VideoDelegate.qml index d6041f0e1..092d7414d 100644 --- a/imports/NeoChat/Component/Timeline/VideoDelegate.qml +++ b/imports/NeoChat/Component/Timeline/VideoDelegate.qml @@ -23,34 +23,33 @@ TimelineContainer { onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions + property bool playOnFinished: false + readonly property bool downloaded: progressInfo && progressInfo.completed + + property bool supportStreaming: true + readonly property int maxWidth: 1000 // TODO messageListView.width + + onDownloadedChanged: { + if (downloaded) { + vid.source = progressInfo.localPath + } + + if (downloaded && playOnFinished) { + playSavedFile() + playOnFinished = false + } + } + innerObject: Video { id: vid - property bool playOnFinished: false - readonly property bool downloaded: progressInfo && progressInfo.completed - - property bool supportStreaming: true - Layout.maximumWidth: videoDelegate.bubbleMaxWidth Layout.fillWidth: true Layout.maximumHeight: Kirigami.Units.gridUnit * 15 Layout.minimumHeight: Kirigami.Units.gridUnit * 5 - onDownloadedChanged: { - if (downloaded) { - vid.source = progressInfo.localPath - } - - if (downloaded && playOnFinished) { - playSavedFile() - playOnFinished = false - } - } - - readonly property int maxWidth: 1000 // TODO messageListView.width - - Layout.preferredWidth: content.info.w > maxWidth ? maxWidth : content.info.w - Layout.preferredHeight: content.info.w > maxWidth ? (content.info.h / content.info.w * maxWidth) : content.info.h + Layout.preferredWidth: (model.content.info.w === undefined || model.content.info.w > videoDelegate.maxWidth) ? videoDelegate.maxWidth : content.info.w + Layout.preferredHeight: model.content.info.w === undefined ? (videoDelegate.maxWidth * 3 / 4) : (model.content.info.w > videoDelegate.maxWidth ? (model.content.info.h / model.content.info.w * videoDelegate.maxWidth) : model.content.info.h) loops: MediaPlayer.Infinite @@ -81,7 +80,7 @@ TimelineContainer { visible: vid.playbackState == MediaPlayer.StoppedState || vid.error != MediaPlayer.NoError - source: "image://mxc/" + content.thumbnailMediaId + source: model.content.thumbnailMediaId ? "image://mxc/" + model.content.thumbnailMediaId : "" fillMode: Image.PreserveAspectFit } @@ -106,7 +105,7 @@ TimelineContainer { Rectangle { anchors.fill: parent - visible: progressInfo.active && !vid.downloaded + visible: progressInfo.active && !videoDelegate.downloaded color: "#BB000000" @@ -130,7 +129,7 @@ TimelineContainer { vid.play() } } else { - vid.downloadAndPlay() + videoDelegate.downloadAndPlay() } } @@ -143,19 +142,19 @@ TimelineContainer { acceptedButtons: Qt.LeftButton onLongPressed: openFileContext(model, parent) } + } - function downloadAndPlay() { - if (vid.downloaded) { - playSavedFile() - } else { - playOnFinished = true - currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) - } - } - - function playSavedFile() { - vid.stop() - vid.play() + function downloadAndPlay() { + if (vid.downloaded) { + playSavedFile() + } else { + playOnFinished = true + currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) } } + + function playSavedFile() { + vid.stop() + vid.play() + } }