Fixed crash when edit album item with photo with invalid dimensions.

- Added InformBox for invalid files.
This commit is contained in:
23rd 2019-04-02 15:46:08 +03:00 committed by John Preston
parent 5d8888bb8b
commit 92f95fa9eb
2 changed files with 18 additions and 3 deletions

View File

@ -163,6 +163,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_pinned_notify" = "Notify all members";
"lng_edit_media" = "Edit media";
"lng_edit_media_album_error" = "This file cannot be saved as a part of an album.";
"lng_intro_about" = "Welcome to the official Telegram Desktop app.\nIt's fast and secure.";
"lng_start_msgs" = "START MESSAGING";

View File

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/input_fields.h"
#include "window/window_controller.h"
#include "ui/widgets/checkbox.h"
#include "confirm_box.h"
EditCaptionBox::EditCaptionBox(
QWidget*,
@ -422,9 +423,22 @@ void EditCaptionBox::createEditMediaButton() {
// Don't rewrite _preparedList if new list is not valid for album.
if (_isAlbum) {
const auto fileMedia = &list.files.front().information->media;
if (!base::get_if<FileMediaInformation::Image>(fileMedia)
&& !base::get_if<FileMediaInformation::Video>(fileMedia)) {
using Info = FileMediaInformation;
const auto media = &list.files.front().information->media;
const auto valid = media->match([&](const Info::Image &data) {
return Storage::ValidateThumbDimensions(
data.data.width(),
data.data.height());
}, [&](const Info::Video &data) {
return true;
}, [](auto &&other) {
return false;
});
if (!valid) {
Ui::show(
Box<InformBox>(lang(lng_edit_media_album_error)),
LayerOption::KeepOther);
return;
}
}