Improve BackgroundType constructor.

This commit is contained in:
levlam 2021-06-10 02:09:16 +03:00
parent 8b3c7b2c39
commit 636aa3f74e
3 changed files with 11 additions and 7 deletions

View File

@ -921,8 +921,7 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou
if (wallpaper_ptr->get_id() == telegram_api::wallPaperNoFile::ID) {
auto wallpaper = move_tl_object_as<telegram_api::wallPaperNoFile>(wallpaper_ptr);
auto settings = std::move(wallpaper->settings_);
if (settings == nullptr) {
if (wallpaper->settings_ == nullptr) {
LOG(ERROR) << "Receive wallPaperNoFile without settings: " << to_string(wallpaper);
return BackgroundId();
}
@ -944,7 +943,7 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou
background.is_creator = false;
background.is_default = true;
background.is_dark = (wallpaper->flags_ & telegram_api::wallPaperNoFile::DARK_MASK) != 0;
background.type = BackgroundType(BackgroundFill(settings.get()));
background.type = BackgroundType(true, false, std::move(wallpaper->settings_));
background.name = background.type.get_link();
add_background(background);
@ -990,7 +989,7 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou
background.is_creator = (flags & telegram_api::wallPaper::CREATOR_MASK) != 0;
background.is_default = (flags & telegram_api::wallPaper::DEFAULT_MASK) != 0;
background.is_dark = (flags & telegram_api::wallPaper::DARK_MASK) != 0;
background.type = BackgroundType(is_pattern, std::move(wallpaper->settings_));
background.type = BackgroundType(false, is_pattern, std::move(wallpaper->settings_));
background.name = std::move(wallpaper->slug_);
background.file_id = document.file_id;
add_background(background);

View File

@ -393,8 +393,13 @@ Result<BackgroundType> BackgroundType::get_background_type(const td_api::Backgro
}
}
BackgroundType::BackgroundType(bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
if (is_pattern) {
BackgroundType::BackgroundType(bool is_fill, bool is_pattern,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
if (is_fill) {
type_ = Type::Fill;
CHECK(settings != nullptr);
fill_ = BackgroundFill(settings.get());
} else if (is_pattern) {
type_ = Type::Pattern;
if (settings) {
fill_ = BackgroundFill(settings.get());

View File

@ -80,7 +80,7 @@ class BackgroundType {
explicit BackgroundType(BackgroundFill fill) : type_(Type::Fill), fill_(fill) {
}
BackgroundType(bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
BackgroundType(bool is_fill, bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
static Result<BackgroundType> get_background_type(const td_api::BackgroundType *background_type);