Allow empty non-null backgrounds in chat event log.

This commit is contained in:
levlam 2024-02-13 16:56:07 +03:00
parent 4198bff4af
commit e1098ef8e9
8 changed files with 24 additions and 16 deletions

View File

@ -11,9 +11,10 @@
namespace td {
BackgroundInfo::BackgroundInfo(Td *td, telegram_api::object_ptr<telegram_api::WallPaper> &&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<telegram_api::WallPaper> &&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);
}

View File

@ -28,7 +28,7 @@ class BackgroundInfo {
BackgroundInfo() : background_id_(), background_type_() {
}
BackgroundInfo(Td *td, telegram_api::object_ptr<telegram_api::WallPaper> &&wallpaper_ptr);
BackgroundInfo(Td *td, telegram_api::object_ptr<telegram_api::WallPaper> &&wallpaper_ptr, bool allow_empty);
td_api::object_ptr<td_api::background> get_background_object(const Td *td) const;

View File

@ -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<td_api::object_ptr<td_api::background>> &&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<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
BackgroundId expected_background_id, const string &expected_background_name,
telegram_api::object_ptr<telegram_api::WallPaper> wallpaper_ptr, bool replace_type) {
telegram_api::object_ptr<telegram_api::WallPaper> 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<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
auto wallpaper = move_tl_object_as<telegram_api::wallPaperNoFile>(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<BackgroundId, BackgroundType> 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<telegram_api::object_ptr<teleg
installed_backgrounds_.clear();
auto wallpapers = telegram_api::move_object_as<telegram_api::account_wallPapers>(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));
}

View File

@ -61,7 +61,7 @@ class BackgroundManager final : public Actor {
std::pair<BackgroundId, BackgroundType> on_get_background(
BackgroundId expected_background_id, const string &expected_background_name,
telegram_api::object_ptr<telegram_api::WallPaper> wallpaper_ptr, bool replace_type);
telegram_api::object_ptr<telegram_api::WallPaper> wallpaper_ptr, bool replace_type, bool allow_empty);
FileSourceId get_background_file_source_id(BackgroundId background_id, int64 access_hash);

View File

@ -466,8 +466,8 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
}
case telegram_api::channelAdminLogEventActionChangeWallpaper::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeWallpaper>(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<td_api::chatEventBackgroundChanged>(
old_background_info.get_chat_background_object(td), new_background_info.get_chat_background_object(td));
}

View File

@ -6793,7 +6793,7 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionSetChatWallPaper::ID: {
auto action = move_tl_object_as<telegram_api::messageActionSetChatWallPaper>(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;
}

View File

@ -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) {

View File

@ -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_;