diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index c417af11a..65583a11c 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -1251,33 +1251,36 @@ void NeoChatRoom::openEventMediaExternally(const QString &eventId) void NeoChatRoom::copyEventMedia(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 = fileTransferInfo(eventId); - if (transferInfo.completed()) { - Clipboard clipboard; - clipboard.setImage(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); - Clipboard clipboard; - clipboard.setImage(transferInfo.localPath); - } - }, - static_cast(Qt::SingleShotConnection)); - } - } + + if (evtIt == messageEvents().rend() || !is(**evtIt)) { + return; + } + const auto event = evtIt->viewAs(); + if (!event->has()) { + return; + } + const auto transferInfo = fileTransferInfo(eventId); + if (transferInfo.completed()) { + Clipboard clipboard; + clipboard.setImage(transferInfo.localPath); + } else { + downloadFile(eventId, + QUrl(u"file:"_s + 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); + Clipboard clipboard; + clipboard.setImage(transferInfo.localPath); + } + }, + Qt::SingleShotConnection); } }