mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
@@ -47,6 +47,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "app.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
|
||||
namespace {
|
||||
|
||||
const auto kAnimatedStickerDimensions = QSize(
|
||||
@@ -320,21 +322,33 @@ void DocumentOpenClickHandler::Open(
|
||||
return;
|
||||
}
|
||||
|
||||
const auto openFile = [&] {
|
||||
const auto media = data->createMediaView();
|
||||
const auto openImageInApp = [&] {
|
||||
if (data->size >= App::kImageSizeLimit) {
|
||||
return false;
|
||||
}
|
||||
const auto &location = data->location(true);
|
||||
if (data->size < App::kImageSizeLimit && location.accessEnable()) {
|
||||
if (!location.isEmpty() && location.accessEnable()) {
|
||||
const auto guard = gsl::finally([&] {
|
||||
location.accessDisable();
|
||||
});
|
||||
const auto path = location.name();
|
||||
if (Core::MimeTypeForFile(path).name().startsWith("image/") && QImageReader(path).canRead()) {
|
||||
if (Core::MimeTypeForFile(path).name().startsWith("image/")
|
||||
&& QImageReader(path).canRead()) {
|
||||
Core::App().showDocument(data, context);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} else if (data->mimeString().startsWith("image/")
|
||||
&& !media->bytes().isEmpty()) {
|
||||
auto bytes = media->bytes();
|
||||
auto buffer = QBuffer(&bytes);
|
||||
if (QImageReader(&buffer).canRead()) {
|
||||
Core::App().showDocument(data, context);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LaunchWithWarning(&data->session(), location.name(), context);
|
||||
return false;
|
||||
};
|
||||
const auto media = data->createMediaView();
|
||||
const auto &location = data->location(true);
|
||||
if (data->isTheme() && media->loaded(true)) {
|
||||
Core::App().showDocument(data, context);
|
||||
@@ -352,11 +366,16 @@ void DocumentOpenClickHandler::Open(
|
||||
} else {
|
||||
Core::App().showDocument(data, context);
|
||||
}
|
||||
} else if (data->saveFromDataSilent()) {
|
||||
openFile();
|
||||
} else if (data->status == FileReady
|
||||
|| data->status == FileDownloadFailed) {
|
||||
DocumentSaveClickHandler::Save(origin, data);
|
||||
} else {
|
||||
data->saveFromDataSilent();
|
||||
if (!openImageInApp()) {
|
||||
if (!data->filepath(true).isEmpty()) {
|
||||
LaunchWithWarning(&data->session(), location.name(), context);
|
||||
} else if (data->status == FileReady
|
||||
|| data->status == FileDownloadFailed) {
|
||||
DocumentSaveClickHandler::Save(origin, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user