Show correct error box when sending file > 4GB.

This commit is contained in:
John Preston 2022-06-16 13:48:11 +04:00
parent 91b7fe5650
commit 0a81246502
8 changed files with 45 additions and 45 deletions

View file

@ -2121,7 +2121,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_downloads_delete_in_cloud" = "They will be deleted from your disk, but will remain accessible in the cloud.";
"lng_send_image_empty" = "Could not send an empty file: {name}";
"lng_send_image_too_large" = "Could not send a file, because it is larger than 1500 MB: {name}";
"lng_send_images_selected#one" = "{count} image selected";
"lng_send_images_selected#other" = "{count} images selected";
"lng_send_photos#one" = "Send {count} photo";

View file

@ -407,6 +407,7 @@ std::unique_ptr<PeerListRow> PublicsController::createRow(
void SimpleLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,
bool premiumPossible,
rpl::producer<QString> title,
rpl::producer<TextWithEntities> text,
const QString &refAddition,
@ -414,7 +415,6 @@ void SimpleLimitBox(
bool fixed = false) {
box->setWidth(st::boxWideWidth);
const auto premiumPossible = session->premiumPossible();
const auto top = fixed
? box->setPinnedToTopContent(object_ptr<Ui::VerticalLayout>(box))
: box->verticalLayout();
@ -469,6 +469,25 @@ void SimpleLimitBox(
}
}
void SimpleLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,
rpl::producer<QString> title,
rpl::producer<TextWithEntities> text,
const QString &refAddition,
const InfographicDescriptor &descriptor,
bool fixed = false) {
SimpleLimitBox(
box,
session,
session->premiumPossible(),
std::move(title),
std::move(text),
refAddition,
descriptor,
fixed);
}
[[nodiscard]] int PinsCount(not_null<Dialogs::MainList*> list) {
return list->pinned()->order().size();
}
@ -877,8 +896,6 @@ void FileSizeLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,
uint64 fileSizeBytes) {
const auto premiumPossible = session->premiumPossible();
const auto defaultLimit = Limit(
session,
"upload_max_fileparts_default",
@ -888,14 +905,19 @@ void FileSizeLimitBox(
"upload_max_fileparts_premium",
8000);
const auto defaultGb = (defaultLimit + 999) / 2000;
const auto premiumGb = (premiumLimit + 999) / 2000;
const auto defaultGb = float64(int(defaultLimit + 999) / 2000);
const auto premiumGb = float64(int(premiumLimit + 999) / 2000);
const auto tooLarge = (fileSizeBytes > premiumLimit * 512ULL * 1024);
const auto showLimit = tooLarge ? premiumGb : defaultGb;
const auto premiumPossible = !tooLarge && session->premiumPossible();
const auto current = (fileSizeBytes && premiumPossible)
? std::clamp(
float64(((fileSizeBytes / uint64(1024 * 1024)) + 999) / 1000),
float64(((fileSizeBytes / uint64(1024 * 1024)) + 499) / 1000),
defaultGb,
premiumGb)
: defaultGb;
: showLimit;
const auto gb = [](int count) {
return tr::lng_file_size_limit(tr::now, lt_count, count);
};
@ -903,7 +925,7 @@ void FileSizeLimitBox(
auto text = rpl::combine(
tr::lng_file_size_limit1(
lt_size,
rpl::single(Ui::Text::Bold(gb(defaultGb))),
rpl::single(Ui::Text::Bold(gb(showLimit))),
Ui::Text::RichLangValue),
(!premiumPossible
? rpl::single(TextWithEntities())
@ -918,13 +940,14 @@ void FileSizeLimitBox(
SimpleLimitBox(
box,
session,
premiumPossible,
tr::lng_file_size_limit_title(),
std::move(text),
"upload_max_fileparts",
{
defaultGb,
current,
premiumGb,
(tooLarge ? showLimit * 2 : premiumGb),
&st::premiumIconFiles,
tr::lng_file_size_limit
});

View file

@ -4903,17 +4903,13 @@ bool HistoryWidget::showSendingFilesError(
tr::now,
lt_name,
list.errorData);
case Error::TooLargeFile: return tr::lng_send_image_too_large(
tr::now,
lt_name,
list.errorData);
case Error::PremiumRequired: return u"(premium)"_q;
case Error::TooLargeFile: return u"(toolarge)"_q;
}
return tr::lng_forward_send_files_cant(tr::now);
}();
if (text.isEmpty()) {
return false;
} else if (text == u"(premium)"_q) {
} else if (text == u"(toolarge)"_q) {
const auto fileSize = list.files.back().size;
controller()->show(Box(FileSizeLimitBox, &session(), fileSize));
return true;

View file

@ -939,17 +939,13 @@ bool RepliesWidget::showSendingFilesError(
tr::now,
lt_name,
list.errorData);
case Error::TooLargeFile: return tr::lng_send_image_too_large(
tr::now,
lt_name,
list.errorData);
case Error::PremiumRequired: return u"(premium)"_q;
case Error::TooLargeFile: return u"(toolarge)"_q;
}
return tr::lng_forward_send_files_cant(tr::now);
}();
if (text.isEmpty()) {
return false;
} else if (text == u"(premium)"_q) {
} else if (text == u"(toolarge)"_q) {
const auto fileSize = list.files.back().size;
controller()->show(Box(FileSizeLimitBox, &session(), fileSize));
return true;

View file

@ -558,17 +558,13 @@ bool ScheduledWidget::showSendingFilesError(
tr::now,
lt_name,
list.errorData);
case Error::TooLargeFile: return tr::lng_send_image_too_large(
tr::now,
lt_name,
list.errorData);
case Error::PremiumRequired: return u"(premium)"_q;
case Error::TooLargeFile: return u"(toolarge)"_q;
}
return tr::lng_forward_send_files_cant(tr::now);
}();
if (text.isEmpty()) {
return false;
} else if (text == u"(premium)"_q) {
} else if (text == u"(toolarge)"_q) {
const auto fileSize = list.files.back().size;
controller()->show(Box(FileSizeLimitBox, &session(), fileSize));
return true;

View file

@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "boxes/send_files_box.h"
#include "boxes/premium_limits_box.h"
#include "ui/boxes/confirm_box.h"
#include "ui/image/image_prepare.h"
#include "lang/lang_keys.h"
@ -1054,16 +1055,10 @@ void FileLoadTask::finish() {
tr::lng_send_image_empty(tr::now, lt_name, _filepath)),
Ui::LayerOption::KeepOther);
removeFromAlbum();
} else if (_result->filesize > kFileSizePremiumLimit) {
} else if (_result->filesize > kFileSizePremiumLimit
|| (_result->filesize > kFileSizeLimit && !premium)) {
Ui::show(
Ui::MakeInformBox(
tr::lng_send_image_too_large(tr::now, lt_name, _filepath)),
Ui::LayerOption::KeepOther);
removeFromAlbum();
} else if (_result->filesize > kFileSizeLimit && !premium) {
Ui::show(
Ui::MakeInformBox(
tr::lng_send_image_too_large(tr::now, lt_name, _filepath)),
Box(FileSizeLimitBox, session, _result->filesize),
Ui::LayerOption::KeepOther);
removeFromAlbum();
} else {

View file

@ -217,14 +217,10 @@ PreparedList PrepareMediaList(
PreparedList::Error::EmptyFile,
file
};
} else if (filesize > kFileSizePremiumLimit) {
return {
PreparedList::Error::TooLargeFile,
file
};
} else if (filesize > kFileSizeLimit && !premium) {
} else if (filesize > kFileSizePremiumLimit
|| (filesize > kFileSizeLimit && !premium)) {
auto errorResult = PreparedList(
PreparedList::Error::PremiumRequired,
PreparedList::Error::TooLargeFile,
QString());
errorResult.files.emplace_back(file);
errorResult.files.back().size = filesize;

View file

@ -91,7 +91,6 @@ struct PreparedList {
Directory,
EmptyFile,
TooLargeFile,
PremiumRequired,
};
PreparedList() = default;