diff --git a/td/telegram/BackgroundInfo.cpp b/td/telegram/BackgroundInfo.cpp index 9140d1e84..747c485bb 100644 --- a/td/telegram/BackgroundInfo.cpp +++ b/td/telegram/BackgroundInfo.cpp @@ -11,9 +11,10 @@ namespace td { -BackgroundInfo::BackgroundInfo(Td *td, telegram_api::object_ptr &&wallpaper_ptr) { - auto background = - td->background_manager_->on_get_background(BackgroundId(), string(), std::move(wallpaper_ptr), false); +BackgroundInfo::BackgroundInfo(Td *td, telegram_api::object_ptr &&wallpaper_ptr, + bool allow_empty) { + auto background = td->background_manager_->on_get_background(BackgroundId(), string(), std::move(wallpaper_ptr), + false, allow_empty); background_id_ = background.first; background_type_ = std::move(background.second); } diff --git a/td/telegram/BackgroundInfo.h b/td/telegram/BackgroundInfo.h index 5a45a0da5..34b9a2d86 100644 --- a/td/telegram/BackgroundInfo.h +++ b/td/telegram/BackgroundInfo.h @@ -28,7 +28,7 @@ class BackgroundInfo { BackgroundInfo() : background_id_(), background_type_() { } - BackgroundInfo(Td *td, telegram_api::object_ptr &&wallpaper_ptr); + BackgroundInfo(Td *td, telegram_api::object_ptr &&wallpaper_ptr, bool allow_empty); td_api::object_ptr get_background_object(const Td *td) const; diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 1b40cd7c4..9057d70e6 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -64,7 +64,7 @@ class GetBackgroundQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->background_manager_->on_get_background(background_id_, background_name_, result_ptr.move_as_ok(), true); + td_->background_manager_->on_get_background(background_id_, background_name_, result_ptr.move_as_ok(), true, false); promise_.set_value(Unit()); } @@ -1057,7 +1057,7 @@ void BackgroundManager::on_uploaded_background_file(FileId file_id, const Backgr Promise> &&promise) { CHECK(wallpaper != nullptr); - auto added_background = on_get_background(BackgroundId(), string(), std::move(wallpaper), true); + auto added_background = on_get_background(BackgroundId(), string(), std::move(wallpaper), true, false); auto background_id = added_background.first; if (!background_id.is_valid()) { td_->file_manager_->cancel_upload(file_id); @@ -1263,8 +1263,11 @@ string BackgroundManager::get_background_name_database_key(const string &name) { std::pair BackgroundManager::on_get_background( BackgroundId expected_background_id, const string &expected_background_name, - telegram_api::object_ptr wallpaper_ptr, bool replace_type) { + telegram_api::object_ptr wallpaper_ptr, bool replace_type, bool allow_empty) { if (wallpaper_ptr == nullptr) { + if (!allow_empty) { + LOG(ERROR) << "Receive unexpected empty background"; + } return {}; } @@ -1272,7 +1275,9 @@ std::pair BackgroundManager::on_get_background( auto wallpaper = move_tl_object_as(wallpaper_ptr); if (wallpaper->settings_ == nullptr) { - LOG(ERROR) << "Receive wallPaperNoFile without settings: " << to_string(wallpaper); + if (!allow_empty) { + LOG(ERROR) << "Receive wallPaperNoFile without settings: " << to_string(wallpaper); + } return {}; } @@ -1310,7 +1315,9 @@ std::pair BackgroundManager::on_get_background( int32 document_id = wallpaper->document_->get_id(); if (document_id == telegram_api::documentEmpty::ID) { - LOG(ERROR) << "Receive " << to_string(wallpaper); + if (!allow_empty) { + LOG(ERROR) << "Receive " << to_string(wallpaper); + } return {}; } CHECK(document_id == telegram_api::document::ID); @@ -1379,7 +1386,7 @@ void BackgroundManager::on_get_backgrounds(Result(wallpapers_ptr); for (auto &wallpaper : wallpapers->wallpapers_) { - auto background = on_get_background(BackgroundId(), string(), std::move(wallpaper), false); + auto background = on_get_background(BackgroundId(), string(), std::move(wallpaper), false, false); if (background.first.is_valid()) { installed_backgrounds_.push_back(std::move(background)); } diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index 1282f4b7f..bc8b2c3aa 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -61,7 +61,7 @@ class BackgroundManager final : public Actor { std::pair on_get_background( BackgroundId expected_background_id, const string &expected_background_name, - telegram_api::object_ptr wallpaper_ptr, bool replace_type); + telegram_api::object_ptr wallpaper_ptr, bool replace_type, bool allow_empty); FileSourceId get_background_file_source_id(BackgroundId background_id, int64 access_hash); diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index 0e17b6065..ee854bead 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -466,8 +466,8 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionChangeWallpaper::ID: { auto action = move_tl_object_as(action_ptr); - auto old_background_info = BackgroundInfo(td, std::move(action->prev_value_)); - auto new_background_info = BackgroundInfo(td, std::move(action->new_value_)); + auto old_background_info = BackgroundInfo(td, std::move(action->prev_value_), true); + auto new_background_info = BackgroundInfo(td, std::move(action->new_value_), true); return td_api::make_object( old_background_info.get_chat_background_object(td), new_background_info.get_chat_background_object(td)); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 39553ca73..f70d20310 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -6793,7 +6793,7 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr(action_ptr); - BackgroundInfo background_info(td, std::move(action->wallpaper_)); + BackgroundInfo background_info(td, std::move(action->wallpaper_), true); if (!background_info.is_valid()) { break; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 174a7834f..16502acc7 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -30090,7 +30090,7 @@ void MessagesManager::on_update_dialog_background(DialogId dialog_id, return; } - set_dialog_background(d, BackgroundInfo(td_, std::move(wallpaper))); + set_dialog_background(d, BackgroundInfo(td_, std::move(wallpaper), true)); } void MessagesManager::set_dialog_background(Dialog *d, BackgroundInfo &&background_info) { diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp index 58a9ac2ff..65f811113 100644 --- a/td/telegram/ThemeManager.cpp +++ b/td/telegram/ThemeManager.cpp @@ -1105,7 +1105,7 @@ ThemeManager::ThemeSettings ThemeManager::get_chat_theme_settings( result.accent_color = settings->accent_color_; bool has_outbox_accent_color = (settings->flags_ & telegram_api::themeSettings::OUTBOX_ACCENT_COLOR_MASK) != 0; result.message_accent_color = (has_outbox_accent_color ? settings->outbox_accent_color_ : result.accent_color); - result.background_info = BackgroundInfo(td_, std::move(settings->wallpaper_)); + result.background_info = BackgroundInfo(td_, std::move(settings->wallpaper_), true); result.base_theme = get_base_theme(settings->base_theme_); result.message_colors = std::move(settings->message_colors_); result.animate_message_colors = settings->message_colors_animated_;