From b4d6b681951aa776f13f5880a84a59cd5e922eec Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 12 Apr 2023 00:59:53 +0300 Subject: [PATCH] Replace dark_theme_brightness with dark_theme_dimming. --- td/generate/scheme/td_api.tl | 8 ++++---- td/telegram/BackgroundInfo.cpp | 3 +-- td/telegram/BackgroundManager.cpp | 8 ++++---- td/telegram/BackgroundManager.h | 2 +- td/telegram/BackgroundType.cpp | 11 ++++------- td/telegram/BackgroundType.h | 17 +++++++---------- td/telegram/LinkManager.cpp | 2 +- td/telegram/Td.cpp | 2 +- td/telegram/cli.cpp | 6 +++--- 9 files changed, 26 insertions(+), 33 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 73e756575..b79150ad0 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -518,8 +518,8 @@ background id:int64 is_default:Bool is_dark:Bool name:string document:document t //@description Contains a list of backgrounds @backgrounds A list of backgrounds backgrounds backgrounds:vector = Backgrounds; -//@description Describes a background set for a specific chat @background The background @dark_theme_brightness Brightness of the background in dark themes, as a percentage; 1-100 -chatBackground background:background dark_theme_brightness:int32 = ChatBackground; +//@description Describes a background set for a specific chat @background The background @dark_theme_dimming Dimmin of the background in dark themes, as a percentage; 0-100 +chatBackground background:background dark_theme_dimming:int32 = ChatBackground; //@description Describes a user profile photo @@ -6907,8 +6907,8 @@ setChatPermissions chat_id:int53 permissions:chatPermissions = Ok; //@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 -//@dark_theme_brightness Brightness of the background in dark themes, as a percentage; 1-100 -setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_brightness:int32 = Ok; +//@dark_theme_dimming Dimming of the background in dark themes, as a percentage; 0-100 +setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_dimming:int32 = 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/BackgroundInfo.cpp b/td/telegram/BackgroundInfo.cpp index 956387bb9..413d083a8 100644 --- a/td/telegram/BackgroundInfo.cpp +++ b/td/telegram/BackgroundInfo.cpp @@ -27,8 +27,7 @@ td_api::object_ptr BackgroundInfo::get_chat_background_o if (background == nullptr) { return nullptr; } - return td_api::make_object(std::move(background), - background_type_.get_dark_theme_brightness()); + return td_api::make_object(std::move(background), background_type_.get_dark_theme_dimming()); } } // namespace td diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index fa54c9371..d3b67af88 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -651,7 +651,7 @@ BackgroundId BackgroundManager::add_local_background(const BackgroundType &type) void BackgroundManager::set_background(const td_api::InputBackground *input_background, const td_api::BackgroundType *background_type, bool for_dark_theme, Promise> &&promise) { - TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, 100)); + TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, 0)); if (input_background == nullptr) { if (background_type == nullptr) { @@ -704,8 +704,8 @@ void BackgroundManager::set_background(const td_api::InputBackground *input_back } void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::InputBackground *input_background, - const td_api::BackgroundType *background_type, - int32 dark_theme_brightness, Promise &&promise) { + const td_api::BackgroundType *background_type, int32 dark_theme_dimming, + Promise &&promise) { if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_background")) { return promise.set_error(Status::Error(400, "Chat not found")); } @@ -732,7 +732,7 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api:: UNREACHABLE(); } - TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, dark_theme_brightness)); + TRY_RESULT_PROMISE(promise, type, BackgroundType::get_background_type(background_type, dark_theme_dimming)); if (input_background == nullptr) { if (type.has_file()) { diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index dc93a3580..c50008d98 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -48,7 +48,7 @@ class BackgroundManager final : public Actor { void reset_backgrounds(Promise &&promise); void set_dialog_background(DialogId dialog_id, const td_api::InputBackground *input_background, - const td_api::BackgroundType *background_type, int32 dark_theme_brightness, + const td_api::BackgroundType *background_type, int32 dark_theme_dimming, Promise &&promise); td_api::object_ptr get_background_object(BackgroundId background_id, bool for_dark_theme, diff --git a/td/telegram/BackgroundType.cpp b/td/telegram/BackgroundType.cpp index 72e353757..a8c93f7ac 100644 --- a/td/telegram/BackgroundType.cpp +++ b/td/telegram/BackgroundType.cpp @@ -336,21 +336,18 @@ StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &t } Result BackgroundType::get_background_type(const td_api::BackgroundType *background_type, - int32 dark_theme_brightness) { + int32 dark_theme_dimming) { if (background_type == nullptr) { return BackgroundType(); } - if (dark_theme_brightness < 1 || dark_theme_brightness > 100) { + if (dark_theme_dimming < 0 || dark_theme_dimming > 100) { return Status::Error(400, "Invalid dark them brightness specified"); } - if (dark_theme_brightness == 100) { - dark_theme_brightness = 0; - } switch (background_type->get_id()) { case td_api::backgroundTypeWallpaper::ID: { auto wallpaper_type = static_cast(background_type); - return BackgroundType(wallpaper_type->is_blurred_, wallpaper_type->is_moving_, dark_theme_brightness); + return BackgroundType(wallpaper_type->is_blurred_, wallpaper_type->is_moving_, dark_theme_dimming); } case td_api::backgroundTypePattern::ID: { auto pattern_type = static_cast(background_type); @@ -364,7 +361,7 @@ Result BackgroundType::get_background_type(const td_api::Backgro case td_api::backgroundTypeFill::ID: { auto fill_type = static_cast(background_type); TRY_RESULT(background_fill, BackgroundFill::get_background_fill(fill_type->fill_.get())); - return BackgroundType(std::move(background_fill), dark_theme_brightness); + return BackgroundType(std::move(background_fill), dark_theme_dimming); } default: UNREACHABLE(); diff --git a/td/telegram/BackgroundType.h b/td/telegram/BackgroundType.h index 4a3b57433..e56420479 100644 --- a/td/telegram/BackgroundType.h +++ b/td/telegram/BackgroundType.h @@ -75,14 +75,14 @@ class BackgroundType { friend StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &type); - BackgroundType(bool is_blurred, bool is_moving, int32 dark_theme_brightness) - : type_(Type::Wallpaper), is_blurred_(is_blurred), is_moving_(is_moving), intensity_(dark_theme_brightness) { + BackgroundType(bool is_blurred, bool is_moving, int32 dark_theme_dimming) + : type_(Type::Wallpaper), is_blurred_(is_blurred), is_moving_(is_moving), intensity_(dark_theme_dimming) { } BackgroundType(bool is_moving, BackgroundFill &&fill, int32 intensity) : type_(Type::Pattern), is_moving_(is_moving), intensity_(intensity), fill_(std::move(fill)) { } - BackgroundType(BackgroundFill &&fill, int32 dark_theme_brightness) - : type_(Type::Fill), fill_(std::move(fill)), intensity_(dark_theme_brightness) { + BackgroundType(BackgroundFill &&fill, int32 dark_theme_dimming) + : type_(Type::Fill), fill_(std::move(fill)), intensity_(dark_theme_dimming) { } public: @@ -91,7 +91,7 @@ class BackgroundType { BackgroundType(bool is_fill, bool is_pattern, telegram_api::object_ptr settings); static Result get_background_type(const td_api::BackgroundType *background_type, - int32 dark_theme_brightness); + int32 dark_theme_dimming); static Result get_local_background_type(Slice name); @@ -124,12 +124,9 @@ class BackgroundType { return fill_.is_dark(); } - int32 get_dark_theme_brightness() const { + int32 get_dark_theme_dimming() const { if (type_ == Type::Pattern) { - return 100; - } - if (intensity_ == 0) { - return 100; + return 0; } return intensity_; } diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 706eeaa9e..a72b3e149 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -2298,7 +2298,7 @@ Result LinkManager::get_background_url(const string &name, if (background_type == nullptr) { return Status::Error(400, "Type must be non-empty"); } - TRY_RESULT(type, BackgroundType::get_background_type(background_type.get(), 100)); + TRY_RESULT(type, BackgroundType::get_background_type(background_type.get(), 0)); auto url = PSTRING() << get_t_me_url() << "bg/"; auto link = type.get_link(); if (type.has_file()) { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9f3dfe728..307bc3af6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6243,7 +6243,7 @@ void Td::on_request(uint64 id, td_api::setChatBackground &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); background_manager_->set_dialog_background(DialogId(request.chat_id_), request.background_.get(), request.type_.get(), - request.dark_theme_brightness_, std::move(promise)); + request.dark_theme_dimming_, std::move(promise)); } void Td::on_request(uint64 id, td_api::setChatTheme &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7b504c785..c114e3f33 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2803,10 +2803,10 @@ class CliClient final : public Actor { ChatId chat_id; InputBackground input_background; BackgroundType background_type; - int32 dark_theme_brightness; - get_args(args, chat_id, input_background, background_type, dark_theme_brightness); + int32 dark_theme_dimming; + 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_brightness)); + dark_theme_dimming)); } else if (op == "gcos") { send_request(td_api::make_object()); } else if (op == "gcoc") {