aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--room.cpp23
-rw-r--r--room.h1
2 files changed, 22 insertions, 2 deletions
diff --git a/room.cpp b/room.cpp
index 79304494..519f08f5 100644
--- a/room.cpp
+++ b/room.cpp
@@ -543,6 +543,25 @@ void Room::resetHighlightCount()
emit highlightCountChanged(this);
}
+QString Room::fileNameToDownload(const QString& eventId)
+{
+ auto evtIt = findInTimeline(eventId);
+ if (evtIt != timelineEdge() &&
+ evtIt->event()->type() == EventType::RoomMessage)
+ {
+ auto* event = static_cast<const RoomMessageEvent*>(evtIt->event());
+ if (event->hasFileContent())
+ {
+ auto* fileInfo = event->content()->fileInfo();
+ return !fileInfo->originalName.isEmpty() ? fileInfo->originalName :
+ !event->plainBody().isEmpty() ? event->plainBody() :
+ QString();
+ }
+ }
+ qWarning() << "No files to download in event" << eventId;
+ return {};
+}
+
FileTransferInfo Room::fileTransferInfo(const QString& id) const
{
auto infoIt = d->fileTransfers.find(id);
@@ -981,8 +1000,8 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename)
auto fileName = !localFilename.isEmpty() ? localFilename.toLocalFile() :
!fileInfo->originalName.isEmpty() ?
(safeTempPrefix + fileInfo->originalName) :
- !event->plainBody().isEmpty() ?
- (safeTempPrefix + event->plainBody()) : QString();
+ !event->plainBody().isEmpty() ? (safeTempPrefix + event->plainBody()) :
+ (safeTempPrefix + fileInfo->mimeType.preferredSuffix());
auto job = connection()->downloadFile(fileInfo->url, fileName);
if (isJobRunning(job))
{
diff --git a/room.h b/room.h
index 0a9bc2b8..a8d58f83 100644
--- a/room.h
+++ b/room.h
@@ -215,6 +215,7 @@ namespace QMatrixClient
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ Q_INVOKABLE QString fileNameToDownload(const QString& eventId);
Q_INVOKABLE FileTransferInfo fileTransferInfo(const QString& id) const;
/** Pretty-prints plain text into HTML