Replace dark_theme_brightness with dark_theme_dimming.

This commit is contained in:
levlam 2023-04-12 00:59:53 +03:00
parent 5df2f3c141
commit b4d6b68195
9 changed files with 26 additions and 33 deletions

View File

@ -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<background> = 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;

View File

@ -27,8 +27,7 @@ td_api::object_ptr<td_api::chatBackground> BackgroundInfo::get_chat_background_o
if (background == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::chatBackground>(std::move(background),
background_type_.get_dark_theme_brightness());
return td_api::make_object<td_api::chatBackground>(std::move(background), background_type_.get_dark_theme_dimming());
}
} // namespace td

View File

@ -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<td_api::object_ptr<td_api::background>> &&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<Unit> &&promise) {
const td_api::BackgroundType *background_type, int32 dark_theme_dimming,
Promise<Unit> &&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()) {

View File

@ -48,7 +48,7 @@ class BackgroundManager final : public Actor {
void reset_backgrounds(Promise<Unit> &&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<Unit> &&promise);
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id, bool for_dark_theme,

View File

@ -336,21 +336,18 @@ StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &t
}
Result<BackgroundType> 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<const td_api::backgroundTypeWallpaper *>(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<const td_api::backgroundTypePattern *>(background_type);
@ -364,7 +361,7 @@ Result<BackgroundType> BackgroundType::get_background_type(const td_api::Backgro
case td_api::backgroundTypeFill::ID: {
auto fill_type = static_cast<const td_api::backgroundTypeFill *>(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();

View File

@ -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<telegram_api::wallPaperSettings> settings);
static Result<BackgroundType> get_background_type(const td_api::BackgroundType *background_type,
int32 dark_theme_brightness);
int32 dark_theme_dimming);
static Result<BackgroundType> 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_;
}

View File

@ -2298,7 +2298,7 @@ Result<string> 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()) {

View File

@ -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) {

View File

@ -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<td_api::setChatBackground>(chat_id, input_background, background_type,
dark_theme_brightness));
dark_theme_dimming));
} else if (op == "gcos") {
send_request(td_api::make_object<td_api::getCountries>());
} else if (op == "gcoc") {