mirror of https://github.com/procxx/kepka.git
Check fields before uploading theme.
This commit is contained in:
parent
9c86f0e0a5
commit
1cda90c3c5
|
@ -571,25 +571,46 @@ Fn<void()> SavePreparedTheme(
|
||||||
session->uploader().uploadMedia(state->id, media);
|
session->uploader().uploadMedia(state->id, media);
|
||||||
};
|
};
|
||||||
|
|
||||||
state->generating = true;
|
const auto save = [=] {
|
||||||
crl::async([=] {
|
state->generating = true;
|
||||||
crl::on_main([=, ready = PrepareTheme(palette, background)]{
|
crl::async([=] {
|
||||||
if (!state->generating) {
|
crl::on_main([=, ready = PrepareTheme(palette, background)]{
|
||||||
return;
|
if (!state->generating) {
|
||||||
}
|
return;
|
||||||
state->generating = false;
|
}
|
||||||
uploadFile(ready);
|
state->generating = false;
|
||||||
|
uploadFile(ready);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const auto checkFields = [=] {
|
||||||
|
state->requestId = api->request(MTPaccount_CreateTheme(
|
||||||
|
MTP_string(fields.slug),
|
||||||
|
MTP_string(fields.title),
|
||||||
|
MTP_inputDocumentEmpty()
|
||||||
|
)).done([=](const MTPTheme &result) {
|
||||||
|
save();
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (error.type() == qstr("THEME_FILE_INVALID")) {
|
||||||
|
save();
|
||||||
|
} else {
|
||||||
|
fail(SaveErrorType::Other, error.type());
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (creating) {
|
||||||
|
checkFields();
|
||||||
|
} else {
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
return [=] {
|
return [=] {
|
||||||
if (state->generating) {
|
state->generating = false;
|
||||||
state->generating = false;
|
api->request(base::take(state->requestId)).cancel();
|
||||||
} else {
|
session->uploader().cancel(state->id);
|
||||||
api->request(base::take(state->requestId)).cancel();
|
state->lifetime.destroy();
|
||||||
session->uploader().cancel(state->id);
|
|
||||||
state->lifetime.destroy();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,10 +818,18 @@ void SaveThemeBox(
|
||||||
});
|
});
|
||||||
const auto fail = crl::guard(box, [=](
|
const auto fail = crl::guard(box, [=](
|
||||||
SaveErrorType type,
|
SaveErrorType type,
|
||||||
const QString &text) {
|
const QString &error) {
|
||||||
*saving = false;
|
*saving = false;
|
||||||
if (!text.isEmpty()) {
|
if (error == qstr("THEME_TITLE_INVALID")) {
|
||||||
Ui::Toast::Show(text);
|
type = SaveErrorType::Name;
|
||||||
|
} else if (error == qstr("THEME_SLUG_INVALID")) {
|
||||||
|
type = SaveErrorType::Link;
|
||||||
|
} else if (error == qstr("THEME_SLUG_OCCUPIED")) {
|
||||||
|
Ui::Toast::Show(
|
||||||
|
tr::lng_create_channel_link_occupied(tr::now));
|
||||||
|
type = SaveErrorType::Link;
|
||||||
|
} else {
|
||||||
|
Ui::Toast::Show(error);
|
||||||
}
|
}
|
||||||
if (type == SaveErrorType::Name) {
|
if (type == SaveErrorType::Name) {
|
||||||
name->showError();
|
name->showError();
|
||||||
|
|
Loading…
Reference in New Issue