Add separate td_api::deleteChatBackground method.

This commit is contained in:
levlam 2023-12-01 00:20:11 +03:00
parent f05f2a67f1
commit 330088d9f8
6 changed files with 30 additions and 12 deletions

View File

@ -7819,14 +7819,17 @@ setChatMessageAutoDeleteTime chat_id:int53 message_auto_delete_time:int32 = Ok;
//@permissions New non-administrator members permissions in the chat
setChatPermissions chat_id:int53 permissions:chatPermissions = Ok;
//@description Changes the background in a specific chat. Supported only in private and secret chats with non-deleted users
//@description Sets the background in a specific chat. Supported only in private and secret chats with non-deleted users
//@chat_id Chat identifier
//@background The input background to use; pass null to create a new filled background or to remove the current background
//@type Background type; pass null to remove the current background
//@background The input background to use; pass null to create a new filled background
//@type Background type; pass null to use default background type for the chosen background
//@dark_theme_dimming Dimming of the background in dark themes, as a percentage; 0-100
//@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
//@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
//@chat_id Chat identifier

View File

@ -763,16 +763,12 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::
TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, dark_theme_dimming));
if (input_background == nullptr) {
if (type.has_file()) {
if (type.has_file() || background_type == nullptr) {
return promise.set_error(Status::Error(400, "Input background must be non-empty for the background type"));
}
if (background_type == nullptr) {
return send_set_dialog_background_query(dialog_id, nullptr, nullptr, MessageId(), for_both, std::move(promise));
} else {
return send_set_dialog_background_query(
dialog_id, telegram_api::make_object<telegram_api::inputWallPaperNoFile>(0),
type.get_input_wallpaper_settings(), MessageId(), for_both, std::move(promise));
}
return send_set_dialog_background_query(dialog_id, telegram_api::make_object<telegram_api::inputWallPaperNoFile>(0),
type.get_input_wallpaper_settings(), MessageId(), for_both,
std::move(promise));
}
switch (input_background->get_id()) {
@ -824,6 +820,11 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::
}
}
void BackgroundManager::delete_dialog_background(DialogId dialog_id, Promise<Unit> &&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<Unit> &&promise) {
TRY_RESULT_PROMISE_ASSIGN(promise, dialog_id, get_background_dialog(dialog_id));

View File

@ -52,6 +52,8 @@ class BackgroundManager final : public Actor {
const td_api::BackgroundType *background_type, int32 dark_theme_dimming, bool for_both,
Promise<Unit> &&promise);
void delete_dialog_background(DialogId dialog_id, Promise<Unit> &&promise);
void revert_dialog_background(DialogId dialog_id, Promise<Unit> &&promise);
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id, bool for_dark_theme,

View File

@ -6534,6 +6534,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::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();

View File

@ -1015,6 +1015,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setChatBackground &request);
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);

View File

@ -3127,6 +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<td_api::setChatBackground>(chat_id, input_background, background_type,
dark_theme_dimming, op == "scbgs"));
} else if (op == "dcb") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::deleteChatBackground>(chat_id));
} else if (op == "rcb") {
ChatId chat_id;
get_args(args, chat_id);