From b82d3ab5ad5500e42d61ecc4ab4a659f8e09282e Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 8 May 2023 07:50:20 +0000 Subject: [PATCH] TempInfo Messageeventmodel Further improvements to the handling of `mediaInfo` in `messageeventmodel`. `blurhash` and `thumbnailInfo` are now replaced with a single `tempInfo` object that contains a single temp source. The priority is thumbnail > `blurhash` > empty if none exist. Fixes network/neochat#235 --- src/models/messageeventmodel.cpp | 35 ++++++++++++++----- .../Component/NeochatMaximizeComponent.qml | 2 +- src/qml/Component/Timeline/ImageDelegate.qml | 2 +- src/qml/Component/Timeline/VideoDelegate.qml | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 2ed41c5f8..1518659fc 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -1150,14 +1150,19 @@ QVariantMap MessageEventModel::getMediaInfoFromFileInfo(const EventContent::File mediaInfo["height"] = castInfo->imageSize.height(); if (!isThumbnail) { - mediaInfo["thumbnailInfo"] = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true); - } - - QString blurhash = castInfo->originalInfoJson["xyz.amorgan.blurhash"].toString(); - if (blurhash.isEmpty()) { - mediaInfo["blurhash"] = QUrl(); - } else { - mediaInfo["blurhash"] = QUrl("image://blurhash/" + blurhash); + QVariantMap tempInfo; + auto thumbnailInfo = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true); + if (thumbnailInfo["source"].toUrl().scheme() == "mxc") { + tempInfo = thumbnailInfo; + } else { + QString blurhash = castInfo->originalInfoJson["xyz.amorgan.blurhash"].toString(); + if (blurhash.isEmpty()) { + tempInfo["source"] = QUrl(); + } else { + tempInfo["source"] = QUrl("image://blurhash/" + blurhash); + } + } + mediaInfo["tempInfo"] = tempInfo; } } } @@ -1168,7 +1173,19 @@ QVariantMap MessageEventModel::getMediaInfoFromFileInfo(const EventContent::File mediaInfo["duration"] = castInfo->duration; if (!isThumbnail) { - mediaInfo["thumbnailInfo"] = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true); + QVariantMap tempInfo; + auto thumbnailInfo = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true); + if (thumbnailInfo["source"].toUrl().scheme() == "mxc") { + tempInfo = thumbnailInfo; + } else { + QString blurhash = castInfo->originalInfoJson["xyz.amorgan.blurhash"].toString(); + if (blurhash.isEmpty()) { + tempInfo["source"] = QUrl(); + } else { + tempInfo["source"] = QUrl("image://blurhash/" + blurhash); + } + } + mediaInfo["tempInfo"] = tempInfo; } } } diff --git a/src/qml/Component/NeochatMaximizeComponent.qml b/src/qml/Component/NeochatMaximizeComponent.qml index edc103849..6fec1ff3d 100644 --- a/src/qml/Component/NeochatMaximizeComponent.qml +++ b/src/qml/Component/NeochatMaximizeComponent.qml @@ -20,7 +20,7 @@ Components.AlbumMaximizeComponent { Components.AlbumModelItem { type: root.modelData.delegateType === MessageEventModel.Image || root.modelData.delegateType === MessageEventModel.Sticker ? Components.AlbumModelItem.Image : Components.AlbumModelItem.Video source: root.modelData.delegateType === MessageEventModel.Video ? modelData.progressInfo.localPath : modelData.mediaInfo.source - tempSource: modelData.mediaInfo.blurhash + tempSource: modelData.mediaInfo.tempInfo.source caption: modelData.display } ] diff --git a/src/qml/Component/Timeline/ImageDelegate.qml b/src/qml/Component/Timeline/ImageDelegate.qml index 542bb5c97..f768d4a9e 100644 --- a/src/qml/Component/Timeline/ImageDelegate.qml +++ b/src/qml/Component/Timeline/ImageDelegate.qml @@ -74,7 +74,7 @@ TimelineContainer { Image { anchors.fill: parent - source: model.mediaInfo.blurhash + source: model.mediaInfo.tempInfo.source visible: parent.status !== Image.Ready } diff --git a/src/qml/Component/Timeline/VideoDelegate.qml b/src/qml/Component/Timeline/VideoDelegate.qml index 7fa261071..946f3c337 100644 --- a/src/qml/Component/Timeline/VideoDelegate.qml +++ b/src/qml/Component/Timeline/VideoDelegate.qml @@ -154,7 +154,7 @@ TimelineContainer { anchors.fill: parent visible: false - source: model.mediaInfo.thumbnailInfo.source + source: model.mediaInfo.tempInfo.source fillMode: Image.PreserveAspectFit }