aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--room.cpp54
-rw-r--r--room.h2
2 files changed, 48 insertions, 8 deletions
diff --git a/room.cpp b/room.cpp
index 51da747e..73591c98 100644
--- a/room.cpp
+++ b/room.cpp
@@ -33,6 +33,7 @@
#include "events/redactionevent.h"
#include "jobs/sendeventjob.h"
#include "jobs/roommessagesjob.h"
+#include "jobs/mediathumbnailjob.h"
#include "jobs/downloadfilejob.h"
#include "avatar.h"
#include "connection.h"
@@ -137,6 +138,8 @@ class Room::Private
// used for both download and upload operations
QHash<QString, FileTransferPrivateInfo> fileTransfers;
+ const RoomMessageEvent* getEventWithFile(const QString& eventId) const;
+
// Convenience methods to work with the membersMap and usersLeft.
// addMember() and removeMember() emit respective Room:: signals
// after a succesful operation.
@@ -546,22 +549,57 @@ void Room::resetHighlightCount()
emit highlightCountChanged(this);
}
-QString Room::fileNameToDownload(const QString& eventId)
+const RoomMessageEvent*
+Room::Private::getEventWithFile(const QString& eventId) const
{
- auto evtIt = findInTimeline(eventId);
- if (evtIt != timelineEdge() &&
+ auto evtIt = q->findInTimeline(eventId);
+ if (evtIt != timeline.rend() &&
evtIt->event()->type() == EventType::RoomMessage)
{
auto* event = static_cast<const RoomMessageEvent*>(evtIt->event());
if (event->hasFileContent())
+ return event;
+ }
+ qWarning() << "No files to download in event" << eventId;
+ return nullptr;
+}
+
+QUrl Room::urlToThumbnail(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ if (event->hasThumbnail())
{
- auto* fileInfo = event->content()->fileInfo();
- return !fileInfo->originalName.isEmpty() ? fileInfo->originalName :
- !event->plainBody().isEmpty() ? event->plainBody() :
- QString();
+ auto* thumbnail = event->content()->thumbnailInfo();
+ Q_ASSERT(thumbnail != nullptr);
+ return MediaThumbnailJob::makeRequestUrl(connection()->homeserver(),
+ thumbnail->url, thumbnail->imageSize);
}
+ qDebug() << "Event" << eventId << "has no thumbnail";
+ return {};
+}
+
+QUrl Room::urlToDownload(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ {
+ auto* fileInfo = event->content()->fileInfo();
+ Q_ASSERT(fileInfo != nullptr);
+ return DownloadFileJob::makeRequestUrl(connection()->homeserver(),
+ fileInfo->url);
+ }
+ return {};
+}
+
+QString Room::fileNameToDownload(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ {
+ auto* fileInfo = event->content()->fileInfo();
+ Q_ASSERT(fileInfo != nullptr);
+ return !fileInfo->originalName.isEmpty() ? fileInfo->originalName :
+ !event->plainBody().isEmpty() ? event->plainBody() :
+ QString();
}
- qWarning() << "No files to download in event" << eventId;
return {};
}
diff --git a/room.h b/room.h
index a8d58f83..a0dad8b3 100644
--- a/room.h
+++ b/room.h
@@ -215,6 +215,8 @@ namespace QMatrixClient
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ Q_INVOKABLE QUrl urlToThumbnail(const QString& eventId);
+ Q_INVOKABLE QUrl urlToDownload(const QString& eventId);
Q_INVOKABLE QString fileNameToDownload(const QString& eventId);
Q_INVOKABLE FileTransferInfo fileTransferInfo(const QString& id) const;