aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp54
1 files changed, 46 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 {};
}