From ed7aff1f246dba18e40ca389683f16fccc20a668 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 23 Oct 2024 16:38:51 +0000 Subject: [PATCH] Updates for further event content changes Adapt to https://github.com/quotient-im/libQuotient/pull/812 --- src/actionshandler.cpp | 6 +++++- src/eventhandler.cpp | 34 +++++++++++++++++++----------- src/models/actionsmodel.cpp | 1 + src/models/messagecontentmodel.cpp | 12 ++++++++--- src/models/messageeventmodel.cpp | 5 +++++ src/neochatroom.cpp | 28 ++++++++++++++++-------- 6 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index 8b7180bb7..6da36a9b8 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -72,11 +72,15 @@ bool ActionsHandler::handleQuickEdit(NeoChatRoom *room, const QString &handledTe for (auto it = room->messageEvents().crbegin(); it != room->messageEvents().crend(); it++) { if (const auto event = eventCast(&**it)) { +#if Quotient_VERSION_MINOR > 8 + if (event->senderId() == room->localMember().id() && event->has()) { +#else if (event->senderId() == room->localMember().id() && event->hasTextContent()) { +#endif QString originalString; if (event->content()) { #if Quotient_VERSION_MINOR > 8 - originalString = static_cast(event->content().get())->body; + originalString = event->get()->body; #else originalString = static_cast(event->content())->body; #endif diff --git a/src/eventhandler.cpp b/src/eventhandler.cpp index b60decf77..bf6d3c4c7 100644 --- a/src/eventhandler.cpp +++ b/src/eventhandler.cpp @@ -225,11 +225,15 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event) { QString body; +#if Quotient_VERSION_MINOR > 8 + if (event.has()) { +#else if (event.hasFileContent()) { +#endif // if filename is given or body is equal to filename, // then body is a caption #if Quotient_VERSION_MINOR > 8 - QString filename = event.fileContent()->originalName; + QString filename = event.get()->originalName; #else QString filename = event.content()->fileInfo()->originalName; #endif @@ -240,10 +244,11 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event) return body; } - if (event.hasTextContent() && event.content()) { #if Quotient_VERSION_MINOR > 8 - body = event.richTextContent()->body; + if (event.has() && event.content()) { + body = event.get()->body; #else + if (event.hasTextContent() && event.content()) { body = static_cast(event.content())->body; #endif } else { @@ -472,10 +477,11 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE { TextHandler textHandler; - if (event.hasFileContent()) { #if Quotient_VERSION_MINOR > 8 - QString fileCaption = event.fileContent()->originalName; + if (event.has()) { + QString fileCaption = event.get()->originalName; #else + if (event.hasFileContent()) { QString fileCaption = event.content()->fileInfo()->originalName; #endif if (fileCaption.isEmpty()) { @@ -488,10 +494,11 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE } QString body; - if (event.hasTextContent() && event.content()) { #if Quotient_VERSION_MINOR > 8 - body = event.richTextContent()->body; + if (event.has() && event.content()) { + body = event.get()->body; #else + if (event.hasTextContent() && event.content()) { body = static_cast(event.content())->body; #endif } else { @@ -708,13 +715,17 @@ QVariantMap EventHandler::getMediaInfoForEvent(const NeoChatRoom *room, const Qu // Get the file info for the event. if (event->is()) { auto roomMessageEvent = eventCast(event); +#if Quotient_VERSION_MINOR > 8 + if (!roomMessageEvent->has()) { +#else if (!roomMessageEvent->hasFileContent()) { +#endif return {}; } #if Quotient_VERSION_MINOR > 8 - const auto content = roomMessageEvent->content(); - QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, static_cast(content.get()), eventId, false, false); + const auto content = roomMessageEvent->get(); + QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, content.get(), eventId, false, false); #else const auto content = static_cast(roomMessageEvent->content()); QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, content, eventId, false, false); @@ -722,8 +733,7 @@ QVariantMap EventHandler::getMediaInfoForEvent(const NeoChatRoom *room, const Qu // if filename isn't specifically given, it is in body // https://spec.matrix.org/latest/client-server-api/#mfile #if Quotient_VERSION_MINOR > 8 - mediaInfo["filename"_ls] = - (roomMessageEvent->fileContent()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : roomMessageEvent->fileContent()->originalName; + mediaInfo["filename"_ls] = content->commonInfo().originalName.isEmpty() ? roomMessageEvent->plainBody() : content->commonInfo().originalName; #else mediaInfo["filename"_ls] = (content->fileInfo()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : content->fileInfo()->originalName; #endif @@ -781,7 +791,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room, // Add media size if available. #if Quotient_VERSION_MINOR > 8 - mediaInfo["size"_ls] = static_cast(fileContent)->payloadSize; + mediaInfo["size"_ls] = fileContent->commonInfo().payloadSize; #else mediaInfo["size"_ls] = static_cast(fileContent)->fileInfo()->payloadSize; #endif diff --git a/src/models/actionsmodel.cpp b/src/models/actionsmodel.cpp index 251d9c591..7862a9359 100644 --- a/src/models/actionsmodel.cpp +++ b/src/models/actionsmodel.cpp @@ -8,6 +8,7 @@ #include "neochatconnection.h" #include "neochatroom.h" #include "roommanager.h" +#include #include #include #include diff --git a/src/models/messagecontentmodel.cpp b/src/models/messagecontentmodel.cpp index e6fd990be..67ffde9ca 100644 --- a/src/models/messagecontentmodel.cpp +++ b/src/models/messagecontentmodel.cpp @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -521,15 +522,16 @@ QList MessageContentModel::componentsForType(MessageComponentT auto fileTransferInfo = m_room->cachedFileTransferInfo(event); #ifndef Q_OS_ANDROID - Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->hasFileContent()); #if Quotient_VERSION_MINOR > 8 - const QMimeType mimeType = roomMessageEvent->fileContent()->mimeType; + Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->has()); + const QMimeType mimeType = roomMessageEvent->get()->mimeType; #else + Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->hasFileContent()); const QMimeType mimeType = roomMessageEvent->content()->fileInfo()->mimeType; #endif if (mimeType.name() == QStringLiteral("text/plain") || mimeType.parentMimeTypes().contains(QStringLiteral("text/plain"))) { #if Quotient_VERSION_MINOR > 8 - QString originalName = roomMessageEvent->fileContent()->originalName; + QString originalName = roomMessageEvent->get()->originalName; #else QString originalName = roomMessageEvent->content()->fileInfo()->originalName; #endif @@ -664,7 +666,11 @@ void MessageContentModel::updateItineraryModel() } if (auto roomMessageEvent = eventCast(event)) { +#if Quotient_VERSION_MINOR > 8 + if (roomMessageEvent->has()) { +#else if (roomMessageEvent->hasFileContent()) { +#endif auto filePath = m_room->cachedFileTransferInfo(event).localPath; if (filePath.isEmpty() && m_itineraryModel != nullptr) { delete m_itineraryModel; diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 61fbd7dfa..0e8f95f2d 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -8,6 +8,7 @@ #include "neochatconfig.h" #include +#include #include #include #include @@ -504,7 +505,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (role == ProgressInfoRole) { if (auto e = eventCast(&evt)) { +#if Quotient_VERSION_MINOR > 8 + if (e->has()) { +#else if (e->hasFileContent()) { +#endif return QVariant::fromValue(m_currentRoom->cachedFileTransferInfo(&evt)); } } diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 3c140bd15..0c118aa42 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -74,10 +74,11 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS const auto m_event = evtIt->viewAs(); QString mxcUrl; if (auto event = eventCast(m_event)) { - if (event->hasFileContent()) { #if Quotient_VERSION_MINOR > 8 - mxcUrl = event->fileContent()->url().toString(); + if (event->has()) { + mxcUrl = event->get()->url().toString(); #else + if (event->hasFileContent()) { mxcUrl = event->content()->fileInfo()->url().toString(); #endif } @@ -221,7 +222,7 @@ QCoro::Task NeoChatRoom::doUploadFile(QUrl url, QString body) url.setScheme("file"_ls); QFileInfo fileInfo(url.isLocalFile() ? url.toLocalFile() : url.toString()); #if Quotient_VERSION_MINOR > 8 - EventContent::Base *content; + EventContent::FileContentBase *content; #else EventContent::TypedBase *content; #endif @@ -240,8 +241,7 @@ QCoro::Task NeoChatRoom::doUploadFile(QUrl url, QString body) content = new EventContent::FileContent(url, fileInfo.size(), mime, fileInfo.fileName()); } #if Quotient_VERSION_MINOR > 8 - QString txnId = - postFile(body.isEmpty() ? url.fileName() : body, std::unique_ptr(static_cast(content))); + QString txnId = postFile(body.isEmpty() ? url.fileName() : body, std::unique_ptr(content)); #else QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content); #endif @@ -376,10 +376,11 @@ bool NeoChatRoom::lastEventIsSpoiler() const { if (auto event = lastEvent()) { if (auto e = eventCast(event)) { - if (e->hasTextContent() && e->content() && e->mimeType().name() == "text/html"_ls) { #if Quotient_VERSION_MINOR > 8 - auto htmlBody = static_cast(e->content().get())->body; + if (e->has() && e->content() && e->mimeType().name() == "text/html"_ls) { + auto htmlBody = e->get()->body; #else + if (e->hasTextContent() && e->content() && e->mimeType().name() == "text/html"_ls) { auto htmlBody = static_cast(e->content())->body; #endif return htmlBody.contains("data-mx-spoiler"_ls); @@ -1445,7 +1446,11 @@ void NeoChatRoom::openEventMediaExternally(const QString &eventId) const auto evtIt = findInTimeline(eventId); if (evtIt != messageEvents().rend() && is(**evtIt)) { const auto event = evtIt->viewAs(); +#if Quotient_VERSION_MINOR > 8 + if (event->has()) { +#else if (event->hasFileContent()) { +#endif const auto transferInfo = cachedFileTransferInfo(event); if (transferInfo.completed()) { UrlHelper helper; @@ -1478,7 +1483,11 @@ void NeoChatRoom::copyEventMedia(const QString &eventId) const auto evtIt = findInTimeline(eventId); if (evtIt != messageEvents().rend() && is(**evtIt)) { const auto event = evtIt->viewAs(); +#if Quotient_VERSION_MINOR > 8 + if (event->has()) { +#else if (event->hasFileContent()) { +#endif const auto transferInfo = fileTransferInfo(eventId); if (transferInfo.completed()) { Clipboard clipboard; @@ -1511,10 +1520,11 @@ FileTransferInfo NeoChatRoom::cachedFileTransferInfo(const Quotient::RoomEvent * QString mxcUrl; int total = 0; if (auto evt = eventCast(event)) { - if (evt->hasFileContent()) { #if Quotient_VERSION_MINOR > 8 - const auto fileContent = evt->fileContent(); + if (evt->has()) { + const auto fileContent = evt->get(); #else + if (evt->hasFileContent()) { const auto fileContent = evt->content()->fileInfo(); #endif