Disabled pasting images with bad size from clipboard for albums.

- Slightly refactored.
This commit is contained in:
23rd 2019-04-10 10:47:44 +03:00 committed by John Preston
parent c6eccc655f
commit c21f5712f8
1 changed files with 13 additions and 4 deletions

View File

@ -629,6 +629,7 @@ bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
if (!_isAllowedEditMedia) { if (!_isAllowedEditMedia) {
return false; return false;
} }
using Error = Storage::PreparedList::Error;
auto list = [&] { auto list = [&] {
auto url = QList<QUrl>(); auto url = QList<QUrl>();
@ -642,9 +643,9 @@ bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
auto result = canAddUrl auto result = canAddUrl
? Storage::PrepareMediaList(url, st::sendMediaPreviewSize) ? Storage::PrepareMediaList(url, st::sendMediaPreviewSize)
: Storage::PreparedList( : Storage::PreparedList(
Storage::PreparedList::Error::EmptyFile, Error::EmptyFile,
QString()); QString());
if (result.error == Storage::PreparedList::Error::None) { if (result.error == Error::None) {
return result; return result;
} else if (data->hasImage()) { } else if (data->hasImage()) {
auto image = qvariant_cast<QImage>(data->imageData()); auto image = qvariant_cast<QImage>(data->imageData());
@ -659,10 +660,18 @@ bool EditCaptionBox::fileFromClipboard(not_null<const QMimeData*> data) {
} }
return result; return result;
}(); }();
_preparedList = std::move(list); if (list.error != Error::None || list.files.empty()) {
if (_preparedList.files.empty()) {
return false; return false;
} }
if (list.files.front().type == Storage::PreparedFile::AlbumType::None
&& _isAlbum) {
Ui::show(
Box<InformBox>(lang(lng_edit_media_album_error)),
LayerOption::KeepOther);
return false;
}
_preparedList = std::move(list);
updateEditPreview(); updateEditPreview();
return true; return true;
} }