diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4ea2b7a61..a99afa7a5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7709,6 +7709,11 @@ setChatPermissions chat_id:int53 permissions:chatPermissions = Ok; //@only_for_self Pass true to set background only for self; pass false to set background for both chat users. Background can be set for both users only by Telegram Premium users setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_dimming:int32 only_for_self:Bool = Ok; +//@description Restores background in a specific chat after it was changed by the other user. Can be called only from messageChatSetBackground messages with the currently set background that was set for both sides by the other user +//-Supported only in private and secret chats with non-deleted users +//@chat_id Chat identifier +revertChatBackground chat_id:int53 = Ok; + //@description Changes the chat theme. Supported only in private and secret chats @chat_id Chat identifier @theme_name Name of the new chat theme; pass an empty string to return the default theme setChatTheme chat_id:int53 theme_name:string = Ok; diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 6f1cc4256..f287f5455 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -111,10 +111,10 @@ class SetChatWallPaperQuery final : public Td::ResultHandler { } void send(DialogId dialog_id, telegram_api::object_ptr input_wallpaper, - telegram_api::object_ptr settings, MessageId old_message_id, - bool for_both) { + telegram_api::object_ptr settings, MessageId old_message_id, bool for_both, + bool revert) { dialog_id_ = dialog_id; - is_remove_ = input_wallpaper == nullptr && settings == nullptr; + is_remove_ = input_wallpaper == nullptr && settings == nullptr && !revert; if (is_remove_) { td_->messages_manager_->on_update_dialog_background(dialog_id_, nullptr); } @@ -136,6 +136,9 @@ class SetChatWallPaperQuery final : public Td::ResultHandler { if (for_both) { flags |= telegram_api::messages_setChatWallPaper::FOR_BOTH_MASK; } + if (revert) { + flags |= telegram_api::messages_setChatWallPaper::REVERT_MASK; + } send_query(G()->net_query_creator().create(telegram_api::messages_setChatWallPaper( flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), std::move(input_wallpaper), std::move(settings), old_message_id.get_server_message_id().get()))); @@ -817,6 +820,37 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api:: } } +void BackgroundManager::revert_dialog_background(DialogId dialog_id, Promise &&promise) { + if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_background")) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Write)) { + return promise.set_error(Status::Error(400, "Can't access the chat")); + } + + switch (dialog_id.get_type()) { + case DialogType::User: + break; + case DialogType::Chat: + case DialogType::Channel: + return promise.set_error(Status::Error(400, "Can't change background in the chat")); + case DialogType::SecretChat: { + auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); + if (!user_id.is_valid()) { + return promise.set_error(Status::Error(400, "Can't access the user")); + } + dialog_id = DialogId(user_id); + break; + } + case DialogType::None: + default: + UNREACHABLE(); + } + + td_->create_handler(std::move(promise)) + ->send(dialog_id, nullptr, nullptr, MessageId(), false, true); +} + void BackgroundManager::do_set_dialog_background(DialogId dialog_id, BackgroundId background_id, BackgroundType type, bool for_both, Promise &&promise) { TRY_STATUS_PROMISE(promise, G()->close_status()); @@ -840,7 +874,7 @@ void BackgroundManager::send_set_dialog_background_query( telegram_api::object_ptr settings, MessageId old_message_id, bool for_both, Promise &&promise) { td_->create_handler(std::move(promise)) - ->send(dialog_id, std::move(input_wallpaper), std::move(settings), old_message_id, for_both); + ->send(dialog_id, std::move(input_wallpaper), std::move(settings), old_message_id, for_both, false); } void BackgroundManager::set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme, diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index 6c7f010dc..64ae94cee 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -52,6 +52,8 @@ class BackgroundManager final : public Actor { const td_api::BackgroundType *background_type, int32 dark_theme_dimming, bool for_both, Promise &&promise); + void revert_dialog_background(DialogId dialog_id, Promise &&promise); + td_api::object_ptr get_background_object(BackgroundId background_id, bool for_dark_theme, const BackgroundType *type) const; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 459ab5935..8e06d6883 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6499,6 +6499,12 @@ void Td::on_request(uint64 id, td_api::setChatBackground &request) { request.dark_theme_dimming_, !request.only_for_self_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::revertChatBackground &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + background_manager_->revert_dialog_background(DialogId(request.chat_id_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setChatTheme &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.theme_name_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 1fb104c1c..a126b7e41 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1006,6 +1006,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setChatBackground &request); + void on_request(uint64 id, const td_api::revertChatBackground &request); + void on_request(uint64 id, td_api::setChatTheme &request); void on_request(uint64 id, td_api::setChatDraftMessage &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 63c22bfa8..f77e5a31f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3109,6 +3109,10 @@ class CliClient final : public Actor { get_args(args, chat_id, input_background, background_type, dark_theme_dimming); send_request(td_api::make_object(chat_id, input_background, background_type, dark_theme_dimming, op == "scbgs")); + } else if (op == "rcb") { + ChatId chat_id; + get_args(args, chat_id); + send_request(td_api::make_object(chat_id)); } else if (op == "gcos") { send_request(td_api::make_object()); } else if (op == "gcoc") {