diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index dc1b72658..c371383c4 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1581,18 +1581,21 @@ void SendFilesBox::captionResized() { update(); } +bool SendFilesBox::canAddUrls(const QList &urls) const { + return !urls.isEmpty() && ranges::find_if( + urls, + [](const QUrl &url) { return !url.isLocalFile(); } + ) == urls.end(); +} + bool SendFilesBox::canAddFiles(not_null data) const { - auto files = 0; - if (data->hasUrls()) { - for (const auto &url : data->urls()) { - if (url.isLocalFile()) { - ++files; - } - } - } else if (data->hasImage()) { - ++files; + const auto urls = data->hasUrls() ? data->urls() : QList(); + auto filesCount = canAddUrls(urls) ? urls.size() : 0; + if (!filesCount && data->hasImage()) { + ++filesCount; } - if (_list.files.size() + files > Storage::MaxAlbumItems()) { + + if (_list.files.size() + filesCount > Storage::MaxAlbumItems()) { return false; } else if (_list.files.size() > 1 && !_albumPreview) { return false; @@ -1605,10 +1608,14 @@ bool SendFilesBox::canAddFiles(not_null data) const { bool SendFilesBox::addFiles(not_null data) { auto list = [&] { - if (data->hasUrls()) { - return Storage::PrepareMediaList( - data->urls(), - st::sendMediaPreviewSize); + const auto urls = data->hasUrls() ? data->urls() : QList(); + auto result = canAddUrls(urls) + ? Storage::PrepareMediaList(urls, st::sendMediaPreviewSize) + : Storage::PreparedList( + Storage::PreparedList::Error::EmptyFile, + QString()); + if (result.error == Storage::PreparedList::Error::None) { + return result; } else if (data->hasImage()) { auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { @@ -1618,9 +1625,7 @@ bool SendFilesBox::addFiles(not_null data) { st::sendMediaPreviewSize); } } - return Storage::PreparedList( - Storage::PreparedList::Error::EmptyFile, - QString()); + return result; }(); if (_list.files.size() + list.files.size() > Storage::MaxAlbumItems()) { return false; diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index 577d60fc3..3c87ec0ff 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -84,6 +84,7 @@ private: void updateControlsGeometry(); bool canAddFiles(not_null data) const; + bool canAddUrls(const QList &urls) const; bool addFiles(not_null data); QString _titleText;