Fixed display photo with modifications as file in attach media preview.

This commit is contained in:
23rd 2022-03-04 18:57:04 +03:00
parent 0e08cffedb
commit f74a75da75
2 changed files with 20 additions and 9 deletions

View file

@ -27,20 +27,29 @@ void OpenWithPreparedFile(
not_null<Ui::PreparedFile*> file,
int previewWidth,
Fn<void()> &&doneCallback) {
if (file->type != Ui::PreparedFile::Type::Photo) {
return;
}
using ImageInfo = Ui::PreparedFileInformation::Image;
const auto image = std::get_if<ImageInfo>(&file->information->media);
if (!image) {
return;
}
const auto photoType = (file->type == Ui::PreparedFile::Type::Photo);
const auto modifiedFileType = (file->type == Ui::PreparedFile::Type::File)
&& !image->modifications.empty();
if (!photoType && !modifiedFileType) {
return;
}
auto callback = [=, done = std::move(doneCallback)](
const PhotoModifications &mods) {
image->modifications = mods;
Storage::UpdateImageDetails(*file, previewWidth);
{
using namespace Ui;
const auto size = file->preview.size();
file->type = ValidateThumbDimensions(size.width(), size.height())
? PreparedFile::Type::Photo
: PreparedFile::Type::File;
}
done();
};
auto copy = image->data;

View file

@ -20,12 +20,14 @@ SingleMediaPreview *SingleMediaPreview::Create(
const PreparedFile &file,
AttachControls::Type type) {
auto preview = QImage();
bool animated = false;
bool animationPreview = false;
auto animated = false;
auto animationPreview = false;
auto hasModifications = false;
if (const auto image = std::get_if<PreparedFileInformation::Image>(
&file.information->media)) {
preview = Editor::ImageModified(image->data, image->modifications);
animated = animationPreview = image->animated;
hasModifications = !image->modifications.empty();
} else if (const auto video = std::get_if<PreparedFileInformation::Video>(
&file.information->media)) {
preview = video->thumbnail;
@ -34,9 +36,9 @@ SingleMediaPreview *SingleMediaPreview::Create(
}
if (preview.isNull()) {
return nullptr;
} else if (!animated && !ValidateThumbDimensions(
preview.width(),
preview.height())) {
} else if (!animated
&& !ValidateThumbDimensions(preview.width(), preview.height())
&& !hasModifications) {
return nullptr;
}
return CreateChild<SingleMediaPreview>(