diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index e08ee4e33..c417af11a 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -1214,34 +1214,38 @@ QByteArray NeoChatRoom::getEventJsonSource(const QString &eventId) void NeoChatRoom::openEventMediaExternally(const QString &eventId) { const auto evtIt = findInTimeline(eventId); - if (evtIt != messageEvents().rend() && is(**evtIt)) { - const auto event = evtIt->viewAs(); - if (event->has()) { - const auto transferInfo = cachedFileTransferInfo(event); - if (transferInfo.completed()) { + if (evtIt == messageEvents().rend()) { + return; + } + + // TODO: Also allow stickers here, once that's fixed in libQuotient + if (!is(**evtIt) || !evtIt->viewAs()->has()) { + return; + } + + const auto transferInfo = cachedFileTransferInfo(evtIt->viewAs()); + if (transferInfo.completed()) { + UrlHelper helper; + helper.openUrl(transferInfo.localPath); + return; + } + downloadFile(eventId, + QUrl(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u'/' + + evtIt->event()->id().replace(u':', u'_').replace(u'/', u'_').replace(u'+', u'_') + fileNameToDownload(eventId))); + connect( + this, + &Room::fileTransferCompleted, + this, + [this, eventId](QString id, QUrl localFile, FileSourceInfo fileMetadata) { + Q_UNUSED(localFile); + Q_UNUSED(fileMetadata); + if (id == eventId) { + auto transferInfo = fileTransferInfo(eventId); UrlHelper helper; helper.openUrl(transferInfo.localPath); - } else { - downloadFile(eventId, - QUrl(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u'/' - + event->id().replace(u':', u'_').replace(u'/', u'_').replace(u'+', u'_') + fileNameToDownload(eventId))); - connect( - this, - &Room::fileTransferCompleted, - this, - [this, eventId](QString id, QUrl localFile, FileSourceInfo fileMetadata) { - Q_UNUSED(localFile); - Q_UNUSED(fileMetadata); - if (id == eventId) { - auto transferInfo = fileTransferInfo(eventId); - UrlHelper helper; - helper.openUrl(transferInfo.localPath); - } - }, - static_cast(Qt::SingleShotConnection)); } - } - } + }, + static_cast(Qt::SingleShotConnection)); } void NeoChatRoom::copyEventMedia(const QString &eventId)