mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Fixed display photo with modifications as file in attach media preview.
This commit is contained in:
parent
0e08cffedb
commit
f74a75da75
2 changed files with 20 additions and 9 deletions
|
@ -27,20 +27,29 @@ void OpenWithPreparedFile(
|
||||||
not_null<Ui::PreparedFile*> file,
|
not_null<Ui::PreparedFile*> file,
|
||||||
int previewWidth,
|
int previewWidth,
|
||||||
Fn<void()> &&doneCallback) {
|
Fn<void()> &&doneCallback) {
|
||||||
|
|
||||||
if (file->type != Ui::PreparedFile::Type::Photo) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||||
const auto image = std::get_if<ImageInfo>(&file->information->media);
|
const auto image = std::get_if<ImageInfo>(&file->information->media);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return;
|
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)](
|
auto callback = [=, done = std::move(doneCallback)](
|
||||||
const PhotoModifications &mods) {
|
const PhotoModifications &mods) {
|
||||||
image->modifications = mods;
|
image->modifications = mods;
|
||||||
Storage::UpdateImageDetails(*file, previewWidth);
|
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();
|
done();
|
||||||
};
|
};
|
||||||
auto copy = image->data;
|
auto copy = image->data;
|
||||||
|
|
|
@ -20,12 +20,14 @@ SingleMediaPreview *SingleMediaPreview::Create(
|
||||||
const PreparedFile &file,
|
const PreparedFile &file,
|
||||||
AttachControls::Type type) {
|
AttachControls::Type type) {
|
||||||
auto preview = QImage();
|
auto preview = QImage();
|
||||||
bool animated = false;
|
auto animated = false;
|
||||||
bool animationPreview = false;
|
auto animationPreview = false;
|
||||||
|
auto hasModifications = false;
|
||||||
if (const auto image = std::get_if<PreparedFileInformation::Image>(
|
if (const auto image = std::get_if<PreparedFileInformation::Image>(
|
||||||
&file.information->media)) {
|
&file.information->media)) {
|
||||||
preview = Editor::ImageModified(image->data, image->modifications);
|
preview = Editor::ImageModified(image->data, image->modifications);
|
||||||
animated = animationPreview = image->animated;
|
animated = animationPreview = image->animated;
|
||||||
|
hasModifications = !image->modifications.empty();
|
||||||
} else if (const auto video = std::get_if<PreparedFileInformation::Video>(
|
} else if (const auto video = std::get_if<PreparedFileInformation::Video>(
|
||||||
&file.information->media)) {
|
&file.information->media)) {
|
||||||
preview = video->thumbnail;
|
preview = video->thumbnail;
|
||||||
|
@ -34,9 +36,9 @@ SingleMediaPreview *SingleMediaPreview::Create(
|
||||||
}
|
}
|
||||||
if (preview.isNull()) {
|
if (preview.isNull()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if (!animated && !ValidateThumbDimensions(
|
} else if (!animated
|
||||||
preview.width(),
|
&& !ValidateThumbDimensions(preview.width(), preview.height())
|
||||||
preview.height())) {
|
&& !hasModifications) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return CreateChild<SingleMediaPreview>(
|
return CreateChild<SingleMediaPreview>(
|
||||||
|
|
Loading…
Add table
Reference in a new issue