diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-05 22:30:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-05 22:30:59 +0900 |
commit | 898f0c73b4d76c091e48c5e767b94d6ad18f582f (patch) | |
tree | 965074fffd32cae0dba11c494ae65b3c67bef28b /room.cpp | |
parent | 818fbda8c43fa76ede72db2e941ec81fe093cc59 (diff) | |
parent | f6b55a3c8fc60dd263954df3359027eff2ef1e18 (diff) | |
download | libquotient-898f0c73b4d76c091e48c5e767b94d6ad18f582f.tar.gz libquotient-898f0c73b4d76c091e48c5e767b94d6ad18f582f.zip |
Merge pull request #170 from QMatrixClient/kitsune-expose-download-urls
Expose download URLs
Diffstat (limited to 'room.cpp')
-rw-r--r-- | room.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
@@ -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 {}; } |