Prepare Image & Video loading for E2EE

Changes the urls to make sure they are decrypted, while making sure that
it is backwards compatible to libQuotient 0.6
This commit is contained in:
Tobias Fella
2022-02-13 23:34:23 +01:00
parent db8b2fd64b
commit faeb1964bd
7 changed files with 28 additions and 16 deletions

View File

@@ -9,8 +9,8 @@ import org.kde.kirigami 2.15 as Kirigami
ApplicationWindow { ApplicationWindow {
id: root id: root
property alias source: image.source
property string filename property string filename
property url localPath
property string blurhash: "" property string blurhash: ""
property int imageWidth: -1 property int imageWidth: -1
property int imageHeight: -1 property int imageHeight: -1
@@ -45,8 +45,6 @@ ApplicationWindow {
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: localPath
Image { Image {
anchors.centerIn: parent anchors.centerIn: parent
width: image.width width: image.width

View File

@@ -35,9 +35,9 @@ TimelineContainer {
innerObject: Image { innerObject: Image {
id: img id: img
Layout.maximumWidth: imageDelegate.bubbleMaxWidth Layout.maximumWidth: imageDelegate.bubbleMaxWidth
source: "image://mxc/" + mediaId Layout.maximumHeight: imageDelegate.bubbleMaxWidth / imageDelegate.info.w * imageDelegate.info.h
source: model.mediaUrl
Image { Image {
anchors.fill: parent anchors.fill: parent
@@ -95,7 +95,7 @@ TimelineContainer {
onTapped: { onTapped: {
fullScreenImage.createObject(parent, { fullScreenImage.createObject(parent, {
filename: eventId, filename: eventId,
localPath: currentRoom.urlToDownload(eventId), source: model.mediaUrl,
blurhash: model.content.info["xyz.amorgan.blurhash"], blurhash: model.content.info["xyz.amorgan.blurhash"],
imageWidth: content.info.w, imageWidth: content.info.w,
imageHeight: content.info.h imageHeight: content.info.h

View File

@@ -55,14 +55,6 @@ TimelineContainer {
fillMode: VideoOutput.PreserveAspectFit fillMode: VideoOutput.PreserveAspectFit
Component.onCompleted: {
if (downloaded) {
source = progressInfo.localPath
} else {
source = currentRoom.urlToMxcUrl(content.url)
}
}
onDurationChanged: { onDurationChanged: {
if (!duration) { if (!duration) {
vid.supportStreaming = false; vid.supportStreaming = false;

View File

@@ -52,7 +52,7 @@ Kirigami.OverlaySheet {
onClicked: { onClicked: {
if (avatarMediaId) { if (avatarMediaId) {
fullScreenImage.createObject(parent, {"filename": displayName, "localPath": room.urlToMxcUrl(avatarUrl)}).showFullScreen() fullScreenImage.createObject(parent, {"filename": displayName, "source": room.urlToMxcUrl(avatarUrl)}).showFullScreen()
} }
} }
} }

View File

@@ -54,6 +54,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[MimeTypeRole] = "mimeType"; roles[MimeTypeRole] = "mimeType";
roles[FormattedBodyRole] = "formattedBody"; roles[FormattedBodyRole] = "formattedBody";
roles[AuthorIdRole] = "authorId"; roles[AuthorIdRole] = "authorId";
roles[MediaUrlRole] = "mediaUrl";
return roles; return roles;
} }
@@ -772,6 +773,23 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return evt.senderId(); return evt.senderId();
} }
if (role == MediaUrlRole) {
#ifdef QUOTIENT_07
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
if (!e->hasFileContent()) {
return QVariant();
}
if (e->content()->originalJson.contains(QStringLiteral("file")) && e->content()->originalJson["file"].toObject().contains(QStringLiteral("url"))) {
return m_currentRoom->makeMediaUrl(e->id(), e->content()->originalJson["file"]["url"].toString());
}
if (e->content()->originalJson.contains(QStringLiteral("url"))) {
return m_currentRoom->makeMediaUrl(e->id(), e->content()->originalJson["url"].toString());
}
}
#endif
return m_currentRoom->urlToDownload(evt.id());
}
return {}; return {};
} }

View File

@@ -44,7 +44,7 @@ public:
IsEditedRole, IsEditedRole,
SourceRole, SourceRole,
MediaUrlRole,
// For debugging // For debugging
EventResolvedTypeRole, EventResolvedTypeRole,
AuthorIdRole, AuthorIdRole,

View File

@@ -311,7 +311,11 @@ QVariantMap NeoChatRoom::getUser(const QString &userID) const
QUrl NeoChatRoom::urlToMxcUrl(const QUrl &mxcUrl) QUrl NeoChatRoom::urlToMxcUrl(const QUrl &mxcUrl)
{ {
#ifdef QUOTIENT_07
return connection()->makeMediaUrl(mxcUrl);
#else
return DownloadFileJob::makeRequestUrl(connection()->homeserver(), mxcUrl); return DownloadFileJob::makeRequestUrl(connection()->homeserver(), mxcUrl);
#endif
} }
QString NeoChatRoom::avatarMediaId() const QString NeoChatRoom::avatarMediaId() const