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

@@ -54,6 +54,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[MimeTypeRole] = "mimeType";
roles[FormattedBodyRole] = "formattedBody";
roles[AuthorIdRole] = "authorId";
roles[MediaUrlRole] = "mediaUrl";
return roles;
}
@@ -772,6 +773,23 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
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 {};
}