Add separate deleteDefaultBackground method.

This commit is contained in:
levlam 2023-12-19 14:38:37 +03:00
parent 0fc3b3adc6
commit b3ce27c4ea
6 changed files with 21 additions and 5 deletions

View File

@ -9143,6 +9143,9 @@ searchBackground name:string = Background;
//@for_dark_theme Pass true if the background is set for a dark theme
setDefaultBackground background:InputBackground type:BackgroundType for_dark_theme:Bool = Background;
//@description Deletes default background for chats @for_dark_theme Pass true if the background is deleted for a dark theme
deleteDefaultBackground for_dark_theme:Bool = Ok;
//@description Returns backgrounds installed by the user @for_dark_theme Pass true to order returned backgrounds for a dark theme
getInstalledBackgrounds for_dark_theme:Bool = Backgrounds;

View File

@ -683,11 +683,7 @@ void BackgroundManager::set_background(const td_api::InputBackground *input_back
TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, 0));
if (input_background == nullptr) {
if (background_type == nullptr) {
set_background_id(BackgroundId(), BackgroundType(), for_dark_theme);
return promise.set_value(nullptr);
}
if (type.has_file()) {
if (background_type == nullptr || type.has_file()) {
return promise.set_error(Status::Error(400, "Input background must be non-empty for the background type"));
}
@ -732,6 +728,11 @@ void BackgroundManager::set_background(const td_api::InputBackground *input_back
}
}
void BackgroundManager::delete_background(bool for_dark_theme, Promise<Unit> &&promise) {
set_background_id(BackgroundId(), BackgroundType(), for_dark_theme);
promise.set_value(Unit());
}
Result<DialogId> BackgroundManager::get_background_dialog(DialogId dialog_id) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_background")) {
return Status::Error(400, "Chat not found");

View File

@ -44,6 +44,8 @@ class BackgroundManager final : public Actor {
void set_background(const td_api::InputBackground *input_background, const td_api::BackgroundType *background_type,
bool for_dark_theme, Promise<td_api::object_ptr<td_api::background>> &&promise);
void delete_background(bool for_dark_theme, Promise<Unit> &&promise);
void remove_background(BackgroundId background_id, Promise<Unit> &&promise);
void reset_backgrounds(Promise<Unit> &&promise);

View File

@ -8790,6 +8790,12 @@ void Td::on_request(uint64 id, td_api::setDefaultBackground &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteDefaultBackground &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
background_manager_->delete_background(request.for_dark_theme_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::removeInstalledBackground &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1599,6 +1599,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setDefaultBackground &request);
void on_request(uint64 id, const td_api::deleteDefaultBackground &request);
void on_request(uint64 id, const td_api::removeInstalledBackground &request);
void on_request(uint64 id, const td_api::resetInstalledBackgrounds &request);

View File

@ -3128,6 +3128,8 @@ class CliClient final : public Actor {
BackgroundType background_type;
get_args(args, input_background, background_type);
send_request(td_api::make_object<td_api::setDefaultBackground>(input_background, background_type, op == "sdbd"));
} else if (op == "ddb" || op == "ddbd") {
send_request(td_api::make_object<td_api::deleteDefaultBackground>(op == "ddbd"));
} else if (op == "rib") {
int64 background_id;
get_args(args, background_id);