From 762c224c10c8ba96ee18a429cae658d1adddb41a Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 1 Dec 2023 01:06:54 +0300 Subject: [PATCH] Add deleteChatBackground.restore_previous. --- td/generate/scheme/td_api.tl | 10 ++++------ td/telegram/BackgroundManager.cpp | 10 ++-------- td/telegram/BackgroundManager.h | 4 +--- td/telegram/Td.cpp | 9 ++------- td/telegram/Td.h | 2 -- td/telegram/cli.cpp | 8 ++------ 6 files changed, 11 insertions(+), 32 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 12b56fc98..19eb85aae 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7827,13 +7827,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 and if set background isn't of the type inputBackgroundPrevious setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_dimming:int32 only_for_self:Bool = Ok; -//@description Deletes background in a specific chat @chat_id Chat identifier -deleteChatBackground chat_id:int53 = Ok; - -//@description Restores background in a specific chat after it was changed by the other user. Supported only in private and secret chats with non-deleted users. -//-Can be called only from messageChatSetBackground messages with the currently set background that was set for both sides by the other user if userFullInfo.set_chat_background == true +//@description Deletes background in a specific chat //@chat_id Chat identifier -revertChatBackground chat_id:int53 = Ok; +//@restore_previous Pass true to restore previously set background. Can be used only in private and secret chats with non-deleted users if userFullInfo.set_chat_background == true. +//-Supposed to be used from messageChatSetBackground messages with the currently set background that was set for both sides by the other user +deleteChatBackground chat_id:int53 restore_previous:Bool = 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 7aafbe4fa..e32fca68c 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -820,16 +820,10 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api:: } } -void BackgroundManager::delete_dialog_background(DialogId dialog_id, Promise &&promise) { +void BackgroundManager::delete_dialog_background(DialogId dialog_id, bool restore_previous, Promise &&promise) { TRY_RESULT_PROMISE_ASSIGN(promise, dialog_id, get_background_dialog(dialog_id)); - send_set_dialog_background_query(dialog_id, nullptr, nullptr, MessageId(), false, std::move(promise)); -} - -void BackgroundManager::revert_dialog_background(DialogId dialog_id, Promise &&promise) { - TRY_RESULT_PROMISE_ASSIGN(promise, dialog_id, get_background_dialog(dialog_id)); - td_->create_handler(std::move(promise)) - ->send(dialog_id, nullptr, nullptr, MessageId(), false, true); + ->send(dialog_id, nullptr, nullptr, MessageId(), false, restore_previous); } void BackgroundManager::do_set_dialog_background(DialogId dialog_id, BackgroundId background_id, BackgroundType type, diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index a91771736..b3bcc1702 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -52,9 +52,7 @@ class BackgroundManager final : public Actor { const td_api::BackgroundType *background_type, int32 dark_theme_dimming, bool for_both, Promise &&promise); - void delete_dialog_background(DialogId dialog_id, Promise &&promise); - - void revert_dialog_background(DialogId dialog_id, Promise &&promise); + void delete_dialog_background(DialogId dialog_id, bool restore_previous, 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 7c0ace04b..80ff279ef 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6537,13 +6537,8 @@ void Td::on_request(uint64 id, td_api::setChatBackground &request) { void Td::on_request(uint64 id, const td_api::deleteChatBackground &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - background_manager_->delete_dialog_background(DialogId(request.chat_id_), 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)); + background_manager_->delete_dialog_background(DialogId(request.chat_id_), request.restore_previous_, + std::move(promise)); } void Td::on_request(uint64 id, td_api::setChatTheme &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 219aff281..c3aff8270 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1017,8 +1017,6 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::deleteChatBackground &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 71ffc8629..829890a89 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3127,14 +3127,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 == "dcb") { + } else if (op == "dcb" || op == "dcbr") { ChatId chat_id; get_args(args, chat_id); - send_request(td_api::make_object(chat_id)); - } else if (op == "rcb") { - ChatId chat_id; - get_args(args, chat_id); - send_request(td_api::make_object(chat_id)); + send_request(td_api::make_object(chat_id, op == "dcbr")); } else if (op == "gcos") { send_request(td_api::make_object()); } else if (op == "gcoc") {