Update for the latest event content changes to libquotient
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <Quotient/events/encryptionevent.h>
|
#include <Quotient/events/encryptionevent.h>
|
||||||
#include <Quotient/events/event.h>
|
#include <Quotient/events/event.h>
|
||||||
|
#include <Quotient/events/eventcontent.h>
|
||||||
#include <Quotient/events/reactionevent.h>
|
#include <Quotient/events/reactionevent.h>
|
||||||
#include <Quotient/events/redactionevent.h>
|
#include <Quotient/events/redactionevent.h>
|
||||||
#include <Quotient/events/roomavatarevent.h>
|
#include <Quotient/events/roomavatarevent.h>
|
||||||
@@ -227,7 +228,11 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
|||||||
if (event.hasFileContent()) {
|
if (event.hasFileContent()) {
|
||||||
// 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
|
||||||
|
QString filename = event.fileContent()->originalName;
|
||||||
|
#else
|
||||||
QString filename = event.content()->fileInfo()->originalName;
|
QString filename = event.content()->fileInfo()->originalName;
|
||||||
|
#endif
|
||||||
QString body = event.plainBody();
|
QString body = event.plainBody();
|
||||||
if (filename.isEmpty() || filename == body) {
|
if (filename.isEmpty() || filename == body) {
|
||||||
return QString();
|
return QString();
|
||||||
@@ -237,7 +242,7 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
|||||||
|
|
||||||
if (event.hasTextContent() && event.content()) {
|
if (event.hasTextContent() && event.content()) {
|
||||||
#if Quotient_VERSION_MINOR > 8
|
#if Quotient_VERSION_MINOR > 8
|
||||||
body = static_cast<const EventContent::TextContent *>(event.content().get())->body;
|
body = event.richTextContent()->body;
|
||||||
#else
|
#else
|
||||||
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
||||||
#endif
|
#endif
|
||||||
@@ -468,10 +473,14 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE
|
|||||||
TextHandler textHandler;
|
TextHandler textHandler;
|
||||||
|
|
||||||
if (event.hasFileContent()) {
|
if (event.hasFileContent()) {
|
||||||
auto fileCaption = event.content()->fileInfo()->originalName;
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
QString fileCaption = event.fileContent()->originalName;
|
||||||
|
#else
|
||||||
|
QString fileCaption = event.content()->fileInfo()->originalName;
|
||||||
|
#endif
|
||||||
if (fileCaption.isEmpty()) {
|
if (fileCaption.isEmpty()) {
|
||||||
fileCaption = event.plainBody();
|
fileCaption = event.plainBody();
|
||||||
} else if (event.content()->fileInfo()->originalName != event.plainBody()) {
|
} else if (fileCaption != event.plainBody()) {
|
||||||
fileCaption = event.plainBody() + " | "_ls + fileCaption;
|
fileCaption = event.plainBody() + " | "_ls + fileCaption;
|
||||||
}
|
}
|
||||||
textHandler.setData(fileCaption);
|
textHandler.setData(fileCaption);
|
||||||
@@ -481,7 +490,7 @@ QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageE
|
|||||||
QString body;
|
QString body;
|
||||||
if (event.hasTextContent() && event.content()) {
|
if (event.hasTextContent() && event.content()) {
|
||||||
#if Quotient_VERSION_MINOR > 8
|
#if Quotient_VERSION_MINOR > 8
|
||||||
body = static_cast<const EventContent::TextContent *>(event.content().get())->body;
|
body = event.richTextContent()->body;
|
||||||
#else
|
#else
|
||||||
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
||||||
#endif
|
#endif
|
||||||
@@ -703,29 +712,39 @@ QVariantMap EventHandler::getMediaInfoForEvent(const NeoChatRoom *room, const Qu
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const EventContent::FileInfo *fileInfo;
|
#if Quotient_VERSION_MINOR > 8
|
||||||
const auto content = roomMessageEvent->content();
|
const auto content = roomMessageEvent->content();
|
||||||
fileInfo = content->fileInfo();
|
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, static_cast<EventContent::FileContent *>(content.get()), eventId, false, false);
|
||||||
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, fileInfo, eventId, false, false);
|
#else
|
||||||
|
const auto content = static_cast<const EventContent::FileContent *>(roomMessageEvent->content());
|
||||||
|
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, content, eventId, false, false);
|
||||||
|
#endif
|
||||||
// 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
|
||||||
mediaInfo["filename"_ls] = (fileInfo->originalName.isEmpty()) ? roomMessageEvent->plainBody() : fileInfo->originalName;
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
mediaInfo["filename"_ls] =
|
||||||
|
(roomMessageEvent->fileContent()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : roomMessageEvent->fileContent()->originalName;
|
||||||
|
#else
|
||||||
|
mediaInfo["filename"_ls] = (content->fileInfo()->originalName.isEmpty()) ? roomMessageEvent->plainBody() : content->fileInfo()->originalName;
|
||||||
|
#endif
|
||||||
|
|
||||||
return mediaInfo;
|
return mediaInfo;
|
||||||
} else if (event->is<StickerEvent>()) {
|
} else if (event->is<StickerEvent>()) {
|
||||||
const EventContent::FileInfo *fileInfo;
|
|
||||||
|
|
||||||
auto stickerEvent = eventCast<const StickerEvent>(event);
|
auto stickerEvent = eventCast<const StickerEvent>(event);
|
||||||
fileInfo = &stickerEvent->image();
|
auto content = &stickerEvent->image();
|
||||||
|
|
||||||
return getMediaInfoFromFileInfo(room, fileInfo, eventId, false, true);
|
return getMediaInfoFromFileInfo(room, content, eventId, false, true);
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
||||||
const EventContent::FileInfo *fileInfo,
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
const Quotient::EventContent::FileContentBase *fileContent,
|
||||||
|
#else
|
||||||
|
const Quotient::EventContent::TypedBase *fileContent,
|
||||||
|
#endif
|
||||||
const QString &eventId,
|
const QString &eventId,
|
||||||
bool isThumbnail,
|
bool isThumbnail,
|
||||||
bool isSticker)
|
bool isSticker)
|
||||||
@@ -733,10 +752,18 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
|||||||
QVariantMap mediaInfo;
|
QVariantMap mediaInfo;
|
||||||
|
|
||||||
// Get the mxc URL for the media.
|
// Get the mxc URL for the media.
|
||||||
if (!fileInfo->url().isValid() || fileInfo->url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
if (!fileContent->url().isValid() || fileContent->url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
||||||
|
#else
|
||||||
|
if (!fileContent->fileInfo()->url().isValid() || fileContent->fileInfo()->url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
||||||
|
#endif
|
||||||
mediaInfo["source"_ls] = QUrl();
|
mediaInfo["source"_ls] = QUrl();
|
||||||
} else {
|
} else {
|
||||||
QUrl source = room->makeMediaUrl(eventId, fileInfo->url());
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
QUrl source = room->makeMediaUrl(eventId, fileContent->url());
|
||||||
|
#else
|
||||||
|
QUrl source = room->makeMediaUrl(eventId, fileContent->fileInfo()->url());
|
||||||
|
#endif
|
||||||
|
|
||||||
if (source.isValid()) {
|
if (source.isValid()) {
|
||||||
mediaInfo["source"_ls] = source;
|
mediaInfo["source"_ls] = source;
|
||||||
@@ -745,7 +772,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mimeType = fileInfo->mimeType;
|
auto mimeType = fileContent->type();
|
||||||
// Add the MIME type for the media if available.
|
// Add the MIME type for the media if available.
|
||||||
mediaInfo["mimeType"_ls] = mimeType.name();
|
mediaInfo["mimeType"_ls] = mimeType.name();
|
||||||
|
|
||||||
@@ -753,45 +780,53 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
|||||||
mediaInfo["mimeIcon"_ls] = mimeType.iconName();
|
mediaInfo["mimeIcon"_ls] = mimeType.iconName();
|
||||||
|
|
||||||
// Add media size if available.
|
// Add media size if available.
|
||||||
mediaInfo["size"_ls] = fileInfo->payloadSize;
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
mediaInfo["size"_ls] = static_cast<const EventContent::FileContent *>(fileContent)->payloadSize;
|
||||||
|
#else
|
||||||
|
mediaInfo["size"_ls] = static_cast<const EventContent::FileContent *>(fileContent)->fileInfo()->payloadSize;
|
||||||
|
#endif
|
||||||
|
|
||||||
mediaInfo["isSticker"_ls] = isSticker;
|
mediaInfo["isSticker"_ls] = isSticker;
|
||||||
|
|
||||||
// Add parameter depending on media type.
|
// Add parameter depending on media type.
|
||||||
if (mimeType.name().contains(QStringLiteral("image"))) {
|
if (mimeType.name().contains(QStringLiteral("image"))) {
|
||||||
if (auto castInfo = static_cast<const EventContent::ImageContent *>(fileInfo)) {
|
if (auto castInfo = static_cast<const EventContent::ImageContent *>(fileContent)) {
|
||||||
|
#if Quotient_VERSION_MINOR > 8
|
||||||
mediaInfo["width"_ls] = castInfo->imageSize.width();
|
mediaInfo["width"_ls] = castInfo->imageSize.width();
|
||||||
mediaInfo["height"_ls] = castInfo->imageSize.height();
|
mediaInfo["height"_ls] = castInfo->imageSize.height();
|
||||||
|
#else
|
||||||
|
const auto imageInfo = static_cast<const EventContent::ImageInfo *>(castInfo->fileInfo());
|
||||||
|
mediaInfo["width"_ls] = imageInfo->imageSize.width();
|
||||||
|
mediaInfo["height"_ls] = imageInfo->imageSize.height();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: Images in certain formats (e.g. WebP) will be erroneously marked as animated, even if they are static.
|
// TODO: Images in certain formats (e.g. WebP) will be erroneously marked as animated, even if they are static.
|
||||||
mediaInfo["animated"_ls] = QMovie::supportedFormats().contains(mimeType.preferredSuffix().toUtf8());
|
mediaInfo["animated"_ls] = QMovie::supportedFormats().contains(mimeType.preferredSuffix().toUtf8());
|
||||||
|
|
||||||
if (!isThumbnail) {
|
QVariantMap tempInfo;
|
||||||
QVariantMap tempInfo;
|
auto thumbnailInfo = getMediaInfoFromTumbnail(room, castInfo->thumbnail, eventId);
|
||||||
auto thumbnailInfo = getMediaInfoFromFileInfo(room, castInfo->thumbnailInfo(), eventId, true);
|
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
||||||
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
tempInfo = thumbnailInfo;
|
||||||
tempInfo = thumbnailInfo;
|
} else {
|
||||||
|
QString blurhash = castInfo->originalInfoJson["xyz.amorgan.blurhash"_ls].toString();
|
||||||
|
if (blurhash.isEmpty()) {
|
||||||
|
tempInfo["source"_ls] = QUrl();
|
||||||
} else {
|
} else {
|
||||||
QString blurhash = castInfo->originalInfoJson["xyz.amorgan.blurhash"_ls].toString();
|
tempInfo["source"_ls] = QUrl("image://blurhash/"_ls + blurhash);
|
||||||
if (blurhash.isEmpty()) {
|
|
||||||
tempInfo["source"_ls] = QUrl();
|
|
||||||
} else {
|
|
||||||
tempInfo["source"_ls] = QUrl("image://blurhash/"_ls + blurhash);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mediaInfo["tempInfo"_ls] = tempInfo;
|
|
||||||
}
|
}
|
||||||
|
mediaInfo["tempInfo"_ls] = tempInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mimeType.name().contains(QStringLiteral("video"))) {
|
if (mimeType.name().contains(QStringLiteral("video"))) {
|
||||||
if (auto castInfo = static_cast<const EventContent::VideoContent *>(fileInfo)) {
|
if (auto castInfo = static_cast<const EventContent::VideoContent *>(fileContent)) {
|
||||||
mediaInfo["width"_ls] = castInfo->imageSize.width();
|
mediaInfo["width"_ls] = castInfo->imageSize.width();
|
||||||
mediaInfo["height"_ls] = castInfo->imageSize.height();
|
mediaInfo["height"_ls] = castInfo->imageSize.height();
|
||||||
mediaInfo["duration"_ls] = castInfo->duration;
|
mediaInfo["duration"_ls] = castInfo->duration;
|
||||||
|
|
||||||
if (!isThumbnail) {
|
if (!isThumbnail) {
|
||||||
QVariantMap tempInfo;
|
QVariantMap tempInfo;
|
||||||
auto thumbnailInfo = getMediaInfoFromFileInfo(room, castInfo->thumbnailInfo(), eventId, true);
|
auto thumbnailInfo = getMediaInfoFromTumbnail(room, castInfo->thumbnail, eventId);
|
||||||
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
||||||
tempInfo = thumbnailInfo;
|
tempInfo = thumbnailInfo;
|
||||||
} else {
|
} else {
|
||||||
@@ -807,7 +842,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mimeType.name().contains(QStringLiteral("audio"))) {
|
if (mimeType.name().contains(QStringLiteral("audio"))) {
|
||||||
if (auto castInfo = static_cast<const EventContent::AudioContent *>(fileInfo)) {
|
if (auto castInfo = static_cast<const EventContent::AudioContent *>(fileContent)) {
|
||||||
mediaInfo["duration"_ls] = castInfo->duration;
|
mediaInfo["duration"_ls] = castInfo->duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -815,6 +850,38 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
|||||||
return mediaInfo;
|
return mediaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap EventHandler::getMediaInfoFromTumbnail(const NeoChatRoom *room, const Quotient::EventContent::Thumbnail &thumbnail, const QString &eventId)
|
||||||
|
{
|
||||||
|
QVariantMap thumbnailInfo;
|
||||||
|
|
||||||
|
if (!thumbnail.url().isValid() || thumbnail.url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
||||||
|
thumbnailInfo["source"_ls] = QUrl();
|
||||||
|
} else {
|
||||||
|
QUrl source = room->makeMediaUrl(eventId, thumbnail.url());
|
||||||
|
|
||||||
|
if (source.isValid()) {
|
||||||
|
thumbnailInfo["source"_ls] = source;
|
||||||
|
} else {
|
||||||
|
thumbnailInfo["source"_ls] = QUrl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto mimeType = thumbnail.mimeType;
|
||||||
|
// Add the MIME type for the media if available.
|
||||||
|
thumbnailInfo["mimeType"_ls] = mimeType.name();
|
||||||
|
|
||||||
|
// Add the MIME type icon if available.
|
||||||
|
thumbnailInfo["mimeIcon"_ls] = mimeType.iconName();
|
||||||
|
|
||||||
|
// Add media size if available.
|
||||||
|
thumbnailInfo["size"_ls] = thumbnail.payloadSize;
|
||||||
|
|
||||||
|
thumbnailInfo["width"_ls] = thumbnail.imageSize.width();
|
||||||
|
thumbnailInfo["height"_ls] = thumbnail.imageSize.height();
|
||||||
|
|
||||||
|
return thumbnailInfo;
|
||||||
|
}
|
||||||
|
|
||||||
bool EventHandler::hasReply(const Quotient::RoomEvent *event, bool showFallbacks)
|
bool EventHandler::hasReply(const Quotient::RoomEvent *event, bool showFallbacks)
|
||||||
{
|
{
|
||||||
if (event == nullptr) {
|
if (event == nullptr) {
|
||||||
|
|||||||
@@ -290,8 +290,13 @@ private:
|
|||||||
|
|
||||||
static QVariantMap getMediaInfoForEvent(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
static QVariantMap getMediaInfoForEvent(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
QVariantMap static getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
QVariantMap static getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
||||||
const Quotient::EventContent::FileInfo *fileInfo,
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
const Quotient::EventContent::FileContentBase *fileContent,
|
||||||
|
#else
|
||||||
|
const Quotient::EventContent::TypedBase *fileContent,
|
||||||
|
#endif
|
||||||
const QString &eventId,
|
const QString &eventId,
|
||||||
bool isThumbnail = false,
|
bool isThumbnail = false,
|
||||||
bool isSticker = false);
|
bool isSticker = false);
|
||||||
|
static QVariantMap getMediaInfoFromTumbnail(const NeoChatRoom *room, const Quotient::EventContent::Thumbnail &thumbnail, const QString &eventId);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -521,10 +521,18 @@ 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->content()->fileInfo() != nullptr);
|
Q_ASSERT(roomMessageEvent->content() != nullptr && roomMessageEvent->hasFileContent());
|
||||||
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
const QMimeType mimeType = roomMessageEvent->fileContent()->mimeType;
|
||||||
|
#else
|
||||||
const QMimeType mimeType = roomMessageEvent->content()->fileInfo()->mimeType;
|
const QMimeType mimeType = roomMessageEvent->content()->fileInfo()->mimeType;
|
||||||
|
#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
|
||||||
|
QString originalName = roomMessageEvent->fileContent()->originalName;
|
||||||
|
#else
|
||||||
QString originalName = roomMessageEvent->content()->fileInfo()->originalName;
|
QString originalName = roomMessageEvent->content()->fileInfo()->originalName;
|
||||||
|
#endif
|
||||||
if (originalName.isEmpty()) {
|
if (originalName.isEmpty()) {
|
||||||
originalName = roomMessageEvent->plainBody();
|
originalName = roomMessageEvent->plainBody();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
|
#include <Quotient/events/eventcontent.h>
|
||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/quotient_common.h>
|
#include <Quotient/quotient_common.h>
|
||||||
#include <qcoro/qcorosignal.h>
|
#include <qcoro/qcorosignal.h>
|
||||||
@@ -74,10 +75,14 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
|||||||
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 (event->hasFileContent()) {
|
||||||
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
mxcUrl = event->fileContent()->url().toString();
|
||||||
|
#else
|
||||||
mxcUrl = event->content()->fileInfo()->url().toString();
|
mxcUrl = event->content()->fileInfo()->url().toString();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else if (auto event = eventCast<const Quotient::StickerEvent>(m_event)) {
|
} else if (auto event = eventCast<const Quotient::StickerEvent>(m_event)) {
|
||||||
mxcUrl = event->image().fileInfo()->url().toString();
|
mxcUrl = event->image().url().toString();
|
||||||
}
|
}
|
||||||
if (mxcUrl.isEmpty()) {
|
if (mxcUrl.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@@ -215,7 +220,11 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body)
|
|||||||
auto mime = QMimeDatabase().mimeTypeForUrl(url);
|
auto mime = QMimeDatabase().mimeTypeForUrl(url);
|
||||||
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
|
||||||
|
EventContent::Base *content;
|
||||||
|
#else
|
||||||
EventContent::TypedBase *content;
|
EventContent::TypedBase *content;
|
||||||
|
#endif
|
||||||
if (mime.name().startsWith("image/"_ls)) {
|
if (mime.name().startsWith("image/"_ls)) {
|
||||||
QImage image(url.toLocalFile());
|
QImage image(url.toLocalFile());
|
||||||
content = new EventContent::ImageContent(url, fileInfo.size(), mime, image.size(), fileInfo.fileName());
|
content = new EventContent::ImageContent(url, fileInfo.size(), mime, image.size(), fileInfo.fileName());
|
||||||
@@ -230,7 +239,12 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body)
|
|||||||
} else {
|
} else {
|
||||||
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
|
||||||
|
QString txnId =
|
||||||
|
postFile(body.isEmpty() ? url.fileName() : body, std::unique_ptr<EventContent::FileContent>(static_cast<EventContent::FileContent *>(content)));
|
||||||
|
#else
|
||||||
QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content);
|
QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content);
|
||||||
|
#endif
|
||||||
setHasFileUploading(true);
|
setHasFileUploading(true);
|
||||||
connect(this, &Room::fileTransferCompleted, [this, txnId](const QString &id, FileSourceInfo) {
|
connect(this, &Room::fileTransferCompleted, [this, txnId](const QString &id, FileSourceInfo) {
|
||||||
if (id == txnId) {
|
if (id == txnId) {
|
||||||
@@ -1498,12 +1512,18 @@ FileTransferInfo NeoChatRoom::cachedFileTransferInfo(const Quotient::RoomEvent *
|
|||||||
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 (evt->hasFileContent()) {
|
||||||
mxcUrl = evt->content()->fileInfo()->url().toString();
|
#if Quotient_VERSION_MINOR > 8
|
||||||
total = evt->content()->fileInfo()->payloadSize;
|
const auto fileContent = evt->fileContent();
|
||||||
|
#else
|
||||||
|
const auto fileContent = evt->content()->fileInfo();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mxcUrl = fileContent->url().toString();
|
||||||
|
total = fileContent->payloadSize;
|
||||||
}
|
}
|
||||||
} else if (auto evt = eventCast<const Quotient::StickerEvent>(event)) {
|
} else if (auto evt = eventCast<const Quotient::StickerEvent>(event)) {
|
||||||
mxcUrl = evt->image().fileInfo()->url().toString();
|
mxcUrl = evt->image().url().toString();
|
||||||
total = evt->image().fileInfo()->payloadSize;
|
total = evt->image().payloadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTransferInfo transferInfo = fileTransferInfo(event->id());
|
FileTransferInfo transferInfo = fileTransferInfo(event->id());
|
||||||
|
|||||||
Reference in New Issue
Block a user