Allow nullptr in BackgroundType::get_background_type.

This commit is contained in:
levlam 2023-04-10 20:53:45 +03:00
parent 45dd4eed9a
commit 0ce6dc6834
3 changed files with 5 additions and 11 deletions

View File

@ -599,16 +599,7 @@ BackgroundId BackgroundManager::add_local_background(const BackgroundType &type)
void BackgroundManager::set_background(const td_api::InputBackground *input_background,
const td_api::BackgroundType *background_type, bool for_dark_theme,
Promise<td_api::object_ptr<td_api::background>> &&promise) {
BackgroundType type;
if (background_type != nullptr) {
auto r_type = BackgroundType::get_background_type(background_type, 100);
if (r_type.is_error()) {
return promise.set_error(r_type.move_as_error());
}
type = r_type.move_as_ok();
} else {
CHECK(!type.has_file());
}
TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, 100));
if (input_background == nullptr) {
if (background_type == nullptr) {

View File

@ -338,7 +338,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &t
Result<BackgroundType> BackgroundType::get_background_type(const td_api::BackgroundType *background_type,
int32 dark_theme_brightness) {
if (background_type == nullptr) {
return Status::Error(400, "Type must be non-empty");
return BackgroundType();
}
if (dark_theme_brightness < 1 || dark_theme_brightness > 100) {
return Status::Error(400, "Invalid dark them brightness specified");

View File

@ -2295,6 +2295,9 @@ void LinkManager::get_link_login_url(const string &url, bool allow_write_access,
Result<string> LinkManager::get_background_url(const string &name,
td_api::object_ptr<td_api::BackgroundType> background_type) {
if (background_type == nullptr) {
return Status::Error(400, "Type must be non-empty");
}
TRY_RESULT(type, BackgroundType::get_background_type(background_type.get(), 100));
auto url = PSTRING() << get_t_me_url() << "bg/";
auto link = type.get_link();