Fix copying images

This commit is contained in:
Tobias Fella
2025-08-11 23:15:44 +02:00
committed by Tobias Fella
parent 648796b9e0
commit ef4f11546f

View File

@@ -1290,16 +1290,21 @@ void NeoChatRoom::openEventMediaExternally(const QString &eventId)
void NeoChatRoom::copyEventMedia(const QString &eventId) void NeoChatRoom::copyEventMedia(const QString &eventId)
{ {
const auto evtIt = findInTimeline(eventId); const auto evtIt = findInTimeline(eventId);
if (evtIt != messageEvents().rend() && is<RoomMessageEvent>(**evtIt)) {
if (evtIt == messageEvents().rend() || !is<RoomMessageEvent>(**evtIt)) {
return;
}
const auto event = evtIt->viewAs<RoomMessageEvent>(); const auto event = evtIt->viewAs<RoomMessageEvent>();
if (event->has<EventContent::FileContent>()) { if (!event->has<EventContent::FileContentBase>()) {
return;
}
const auto transferInfo = fileTransferInfo(eventId); const auto transferInfo = fileTransferInfo(eventId);
if (transferInfo.completed()) { if (transferInfo.completed()) {
Clipboard clipboard; Clipboard clipboard;
clipboard.setImage(transferInfo.localPath); clipboard.setImage(transferInfo.localPath);
} else { } else {
downloadFile(eventId, downloadFile(eventId,
QUrl(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u'/' QUrl(u"file:"_s + QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u'/'
+ event->id().replace(u':', u'_').replace(u'/', u'_').replace(u'+', u'_') + fileNameToDownload(eventId))); + event->id().replace(u':', u'_').replace(u'/', u'_').replace(u'+', u'_') + fileNameToDownload(eventId)));
connect( connect(
this, this,
@@ -1314,9 +1319,7 @@ void NeoChatRoom::copyEventMedia(const QString &eventId)
clipboard.setImage(transferInfo.localPath); clipboard.setImage(transferInfo.localPath);
} }
}, },
static_cast<Qt::ConnectionType>(Qt::SingleShotConnection)); Qt::SingleShotConnection);
}
}
} }
} }