Updates for further event content changes

Adapt to https://github.com/quotient-im/libQuotient/pull/812
This commit is contained in:
James Graham
2024-10-23 16:38:51 +00:00
parent 33f4be0d88
commit ed7aff1f24
6 changed files with 61 additions and 25 deletions

View File

@@ -72,11 +72,15 @@ bool ActionsHandler::handleQuickEdit(NeoChatRoom *room, const QString &handledTe
for (auto it = room->messageEvents().crbegin(); it != room->messageEvents().crend(); it++) { for (auto it = room->messageEvents().crbegin(); it != room->messageEvents().crend(); it++) {
if (const auto event = eventCast<const RoomMessageEvent>(&**it)) { if (const auto event = eventCast<const RoomMessageEvent>(&**it)) {
#if Quotient_VERSION_MINOR > 8
if (event->senderId() == room->localMember().id() && event->has<EventContent::TextContent>()) {
#else
if (event->senderId() == room->localMember().id() && event->hasTextContent()) { if (event->senderId() == room->localMember().id() && event->hasTextContent()) {
#endif
QString originalString; QString originalString;
if (event->content()) { if (event->content()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content().get())->body; originalString = event->get<EventContent::TextContent>()->body;
#else #else
originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content())->body; originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content())->body;
#endif #endif

View File

@@ -225,11 +225,15 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
{ {
QString body; QString body;
#if Quotient_VERSION_MINOR > 8
if (event.has<EventContent::FileContent>()) {
#else
if (event.hasFileContent()) { if (event.hasFileContent()) {
#endif
// if filename is given or body is equal to filename, // if filename is given or body is equal to filename,
// then body is a caption // then body is a caption
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
QString filename = event.fileContent()->originalName; QString filename = event.get<EventContent::FileContent>()->originalName;
#else #else
QString filename = event.content()->fileInfo()->originalName; QString filename = event.content()->fileInfo()->originalName;
#endif #endif
@@ -240,10 +244,11 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
return body; return body;
} }
if (event.hasTextContent() && event.content()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
body = event.richTextContent()->body; if (event.has<EventContent::TextContent>() && event.content()) {
body = event.get<EventContent::TextContent>()->body;
#else #else
if (event.hasTextContent() && event.content()) {
body = static_cast<const EventContent::TextContent *>(event.content())->body; body = static_cast<const EventContent::TextContent *>(event.content())->body;
#endif #endif
} else { } else {
@@ -472,10 +477,11 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE
{ {
TextHandler textHandler; TextHandler textHandler;
if (event.hasFileContent()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
QString fileCaption = event.fileContent()->originalName; if (event.has<EventContent::FileContent>()) {
QString fileCaption = event.get<EventContent::FileContent>()->originalName;
#else #else
if (event.hasFileContent()) {
QString fileCaption = event.content()->fileInfo()->originalName; QString fileCaption = event.content()->fileInfo()->originalName;
#endif #endif
if (fileCaption.isEmpty()) { if (fileCaption.isEmpty()) {
@@ -488,10 +494,11 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE
} }
QString body; QString body;
if (event.hasTextContent() && event.content()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
body = event.richTextContent()->body; if (event.has<EventContent::TextContent>() && event.content()) {
body = event.get<EventContent::TextContent>()->body;
#else #else
if (event.hasTextContent() && event.content()) {
body = static_cast<const EventContent::TextContent *>(event.content())->body; body = static_cast<const EventContent::TextContent *>(event.content())->body;
#endif #endif
} else { } else {
@@ -708,13 +715,17 @@ QVariantMap EventHandler::getMediaInfoForEvent(const NeoChatRoom *room, const Qu
// Get the file info for the event. // Get the file info for the event.
if (event->is<RoomMessageEvent>()) { if (event->is<RoomMessageEvent>()) {
auto roomMessageEvent = eventCast<const RoomMessageEvent>(event); auto roomMessageEvent = eventCast<const RoomMessageEvent>(event);
#if Quotient_VERSION_MINOR > 8
if (!roomMessageEvent->has<EventContent::FileContentBase>()) {
#else
if (!roomMessageEvent->hasFileContent()) { if (!roomMessageEvent->hasFileContent()) {
#endif
return {}; return {};
} }
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
const auto content = roomMessageEvent->content(); const auto content = roomMessageEvent->get<EventContent::FileContentBase>();
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, static_cast<EventContent::FileContent *>(content.get()), eventId, false, false); QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, content.get(), eventId, false, false);
#else #else
const auto content = static_cast<const EventContent::FileContent *>(roomMessageEvent->content()); const auto content = static_cast<const EventContent::FileContent *>(roomMessageEvent->content());
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, content, eventId, false, false); 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 // if filename isn't specifically given, it is in body
// https://spec.matrix.org/latest/client-server-api/#mfile // https://spec.matrix.org/latest/client-server-api/#mfile
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
mediaInfo["filename"_ls] = mediaInfo["filename"_ls] = content->commonInfo().originalName.isEmpty() ? roomMessageEvent->plainBody() : content->commonInfo().originalName;
(roomMessageEvent->fileContent()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : roomMessageEvent->fileContent()->originalName;
#else #else
mediaInfo["filename"_ls] = (content->fileInfo()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : content->fileInfo()->originalName; mediaInfo["filename"_ls] = (content->fileInfo()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : content->fileInfo()->originalName;
#endif #endif
@@ -781,7 +791,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
// Add media size if available. // Add media size if available.
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
mediaInfo["size"_ls] = static_cast<const EventContent::FileContent *>(fileContent)->payloadSize; mediaInfo["size"_ls] = fileContent->commonInfo().payloadSize;
#else #else
mediaInfo["size"_ls] = static_cast<const EventContent::FileContent *>(fileContent)->fileInfo()->payloadSize; mediaInfo["size"_ls] = static_cast<const EventContent::FileContent *>(fileContent)->fileInfo()->payloadSize;
#endif #endif

View File

@@ -8,6 +8,7 @@
#include "neochatconnection.h" #include "neochatconnection.h"
#include "neochatroom.h" #include "neochatroom.h"
#include "roommanager.h" #include "roommanager.h"
#include <Quotient/events/eventcontent.h>
#include <Quotient/events/roommemberevent.h> #include <Quotient/events/roommemberevent.h>
#include <Quotient/events/roompowerlevelsevent.h> #include <Quotient/events/roompowerlevelsevent.h>
#include <Quotient/user.h> #include <Quotient/user.h>

View File

@@ -7,6 +7,7 @@
#include <QImageReader> #include <QImageReader>
#include <Quotient/events/eventcontent.h>
#include <Quotient/events/redactionevent.h> #include <Quotient/events/redactionevent.h>
#include <Quotient/events/roommessageevent.h> #include <Quotient/events/roommessageevent.h>
#include <Quotient/events/stickerevent.h> #include <Quotient/events/stickerevent.h>
@@ -521,15 +522,16 @@ QList<MessageComponent> MessageContentModel::componentsForType(MessageComponentT
auto fileTransferInfo = m_room->cachedFileTransferInfo(event); auto fileTransferInfo = m_room->cachedFileTransferInfo(event);
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->hasFileContent());
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
const QMimeType mimeType = roomMessageEvent->fileContent()->mimeType; Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->has<EventContent::FileContent>());
const QMimeType mimeType = roomMessageEvent->get<EventContent::FileContent>()->mimeType;
#else #else
Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->hasFileContent());
const QMimeType mimeType = roomMessageEvent->content()->fileInfo()->mimeType; const QMimeType mimeType = roomMessageEvent->content()->fileInfo()->mimeType;
#endif #endif
if (mimeType.name() == QStringLiteral("text/plain") || mimeType.parentMimeTypes().contains(QStringLiteral("text/plain"))) { if (mimeType.name() == QStringLiteral("text/plain") || mimeType.parentMimeTypes().contains(QStringLiteral("text/plain"))) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
QString originalName = roomMessageEvent->fileContent()->originalName; QString originalName = roomMessageEvent->get<EventContent::FileContent>()->originalName;
#else #else
QString originalName = roomMessageEvent->content()->fileInfo()->originalName; QString originalName = roomMessageEvent->content()->fileInfo()->originalName;
#endif #endif
@@ -664,7 +666,11 @@ void MessageContentModel::updateItineraryModel()
} }
if (auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event)) { if (auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
#if Quotient_VERSION_MINOR > 8
if (roomMessageEvent->has<EventContent::FileContent>()) {
#else
if (roomMessageEvent->hasFileContent()) { if (roomMessageEvent->hasFileContent()) {
#endif
auto filePath = m_room->cachedFileTransferInfo(event).localPath; auto filePath = m_room->cachedFileTransferInfo(event).localPath;
if (filePath.isEmpty() && m_itineraryModel != nullptr) { if (filePath.isEmpty() && m_itineraryModel != nullptr) {
delete m_itineraryModel; delete m_itineraryModel;

View File

@@ -8,6 +8,7 @@
#include "neochatconfig.h" #include "neochatconfig.h"
#include <Quotient/csapi/rooms.h> #include <Quotient/csapi/rooms.h>
#include <Quotient/events/eventcontent.h>
#include <Quotient/events/redactionevent.h> #include <Quotient/events/redactionevent.h>
#include <Quotient/events/roommessageevent.h> #include <Quotient/events/roommessageevent.h>
#include <Quotient/events/stickerevent.h> #include <Quotient/events/stickerevent.h>
@@ -504,7 +505,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
if (role == ProgressInfoRole) { if (role == ProgressInfoRole) {
if (auto e = eventCast<const RoomMessageEvent>(&evt)) { if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
#if Quotient_VERSION_MINOR > 8
if (e->has<EventContent::FileContent>()) {
#else
if (e->hasFileContent()) { if (e->hasFileContent()) {
#endif
return QVariant::fromValue(m_currentRoom->cachedFileTransferInfo(&evt)); return QVariant::fromValue(m_currentRoom->cachedFileTransferInfo(&evt));
} }
} }

View File

@@ -74,10 +74,11 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
const auto m_event = evtIt->viewAs<RoomEvent>(); const auto m_event = evtIt->viewAs<RoomEvent>();
QString mxcUrl; QString mxcUrl;
if (auto event = eventCast<const Quotient::RoomMessageEvent>(m_event)) { if (auto event = eventCast<const Quotient::RoomMessageEvent>(m_event)) {
if (event->hasFileContent()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
mxcUrl = event->fileContent()->url().toString(); if (event->has<EventContent::FileContentBase>()) {
mxcUrl = event->get<EventContent::FileContentBase>()->url().toString();
#else #else
if (event->hasFileContent()) {
mxcUrl = event->content()->fileInfo()->url().toString(); mxcUrl = event->content()->fileInfo()->url().toString();
#endif #endif
} }
@@ -221,7 +222,7 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body)
url.setScheme("file"_ls); url.setScheme("file"_ls);
QFileInfo fileInfo(url.isLocalFile() ? url.toLocalFile() : url.toString()); QFileInfo fileInfo(url.isLocalFile() ? url.toLocalFile() : url.toString());
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
EventContent::Base *content; EventContent::FileContentBase *content;
#else #else
EventContent::TypedBase *content; EventContent::TypedBase *content;
#endif #endif
@@ -240,8 +241,7 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body)
content = new EventContent::FileContent(url, fileInfo.size(), mime, fileInfo.fileName()); content = new EventContent::FileContent(url, fileInfo.size(), mime, fileInfo.fileName());
} }
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
QString txnId = QString txnId = postFile(body.isEmpty() ? url.fileName() : body, std::unique_ptr<EventContent::FileContentBase>(content));
postFile(body.isEmpty() ? url.fileName() : body, std::unique_ptr<EventContent::FileContent>(static_cast<EventContent::FileContent *>(content)));
#else #else
QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content); QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content);
#endif #endif
@@ -376,10 +376,11 @@ bool NeoChatRoom::lastEventIsSpoiler() const
{ {
if (auto event = lastEvent()) { if (auto event = lastEvent()) {
if (auto e = eventCast<const RoomMessageEvent>(event)) { if (auto e = eventCast<const RoomMessageEvent>(event)) {
if (e->hasTextContent() && e->content() && e->mimeType().name() == "text/html"_ls) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
auto htmlBody = static_cast<const Quotient::EventContent::TextContent *>(e->content().get())->body; if (e->has<EventContent::TextContent>() && e->content() && e->mimeType().name() == "text/html"_ls) {
auto htmlBody = e->get<EventContent::TextContent>()->body;
#else #else
if (e->hasTextContent() && e->content() && e->mimeType().name() == "text/html"_ls) {
auto htmlBody = static_cast<const Quotient::EventContent::TextContent *>(e->content())->body; auto htmlBody = static_cast<const Quotient::EventContent::TextContent *>(e->content())->body;
#endif #endif
return htmlBody.contains("data-mx-spoiler"_ls); return htmlBody.contains("data-mx-spoiler"_ls);
@@ -1445,7 +1446,11 @@ void NeoChatRoom::openEventMediaExternally(const QString &eventId)
const auto evtIt = findInTimeline(eventId); const auto evtIt = findInTimeline(eventId);
if (evtIt != messageEvents().rend() && is<RoomMessageEvent>(**evtIt)) { if (evtIt != messageEvents().rend() && is<RoomMessageEvent>(**evtIt)) {
const auto event = evtIt->viewAs<RoomMessageEvent>(); const auto event = evtIt->viewAs<RoomMessageEvent>();
#if Quotient_VERSION_MINOR > 8
if (event->has<EventContent::FileContent>()) {
#else
if (event->hasFileContent()) { if (event->hasFileContent()) {
#endif
const auto transferInfo = cachedFileTransferInfo(event); const auto transferInfo = cachedFileTransferInfo(event);
if (transferInfo.completed()) { if (transferInfo.completed()) {
UrlHelper helper; UrlHelper helper;
@@ -1478,7 +1483,11 @@ void NeoChatRoom::copyEventMedia(const QString &eventId)
const auto evtIt = findInTimeline(eventId); const auto evtIt = findInTimeline(eventId);
if (evtIt != messageEvents().rend() && is<RoomMessageEvent>(**evtIt)) { if (evtIt != messageEvents().rend() && is<RoomMessageEvent>(**evtIt)) {
const auto event = evtIt->viewAs<RoomMessageEvent>(); const auto event = evtIt->viewAs<RoomMessageEvent>();
#if Quotient_VERSION_MINOR > 8
if (event->has<EventContent::FileContent>()) {
#else
if (event->hasFileContent()) { if (event->hasFileContent()) {
#endif
const auto transferInfo = fileTransferInfo(eventId); const auto transferInfo = fileTransferInfo(eventId);
if (transferInfo.completed()) { if (transferInfo.completed()) {
Clipboard clipboard; Clipboard clipboard;
@@ -1511,10 +1520,11 @@ FileTransferInfo NeoChatRoom::cachedFileTransferInfo(const Quotient::RoomEvent *
QString mxcUrl; QString mxcUrl;
int total = 0; int total = 0;
if (auto evt = eventCast<const Quotient::RoomMessageEvent>(event)) { if (auto evt = eventCast<const Quotient::RoomMessageEvent>(event)) {
if (evt->hasFileContent()) {
#if Quotient_VERSION_MINOR > 8 #if Quotient_VERSION_MINOR > 8
const auto fileContent = evt->fileContent(); if (evt->has<EventContent::FileContent>()) {
const auto fileContent = evt->get<EventContent::FileContent>();
#else #else
if (evt->hasFileContent()) {
const auto fileContent = evt->content()->fileInfo(); const auto fileContent = evt->content()->fileInfo();
#endif #endif