Replace add_fill_background with add_local_background.

This commit is contained in:
levlam 2021-06-10 04:44:39 +03:00
parent aba5b1ab7c
commit 75fc042e09
4 changed files with 29 additions and 24 deletions

View File

@ -446,14 +446,14 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::search_background(con
}
if (is_background_name_local(slug)) {
auto r_fill = BackgroundFill::get_background_fill(name);
if (r_fill.is_error()) {
promise.set_error(r_fill.move_as_error());
auto r_type = BackgroundType::get_local_background_type(name);
if (r_type.is_error()) {
promise.set_error(r_type.move_as_error());
return {};
}
auto background_id = add_fill_background(r_fill.ok());
auto background_id = add_local_background(r_type.ok());
promise.set_value(Unit());
return {background_id, BackgroundType(r_fill.ok())};
return {background_id, r_type.ok()};
}
if (G()->parameters().use_file_db && loaded_from_database_backgrounds_.count(slug) == 0) {
@ -549,18 +549,18 @@ BackgroundId BackgroundManager::get_next_local_background_id() {
return max_local_background_id_;
}
BackgroundId BackgroundManager::add_fill_background(const BackgroundFill &fill) {
return add_fill_background(fill, false, fill.is_dark());
BackgroundId BackgroundManager::add_local_background(const BackgroundType &type) {
return add_local_background(type, false, type.is_dark());
}
BackgroundId BackgroundManager::add_fill_background(const BackgroundFill &fill, bool is_default, bool is_dark) {
BackgroundId BackgroundManager::add_local_background(const BackgroundType &type, bool is_default, bool is_dark) {
Background background;
background.id = get_next_local_background_id();
background.is_creator = true;
background.is_default = is_default;
background.is_dark = is_dark;
background.type = BackgroundType(fill);
background.name = background.type.get_link();
background.type = type;
background.name = type.get_link();
add_background(background);
return background.id;
@ -592,7 +592,7 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
return BackgroundId();
}
auto background_id = add_fill_background(type.get_background_fill());
auto background_id = add_local_background(type);
set_background_id(background_id, type, for_dark_theme);
promise.set_value(Unit());
return background_id;
@ -644,7 +644,7 @@ BackgroundId BackgroundManager::set_background(BackgroundId background_id, Backg
}
if (!type.has_file()) {
type = background->type;
} else if (background->type.has_equal_type(type)) {
} else if (!background->type.has_equal_type(type)) {
promise.set_error(Status::Error(400, "Background type mismatch"));
return BackgroundId();
}

View File

@ -110,9 +110,9 @@ class BackgroundManager : public Actor {
BackgroundId get_next_local_background_id();
BackgroundId add_fill_background(const BackgroundFill &fill);
BackgroundId add_local_background(const BackgroundType &type);
BackgroundId add_fill_background(const BackgroundFill &fill, bool is_default, bool is_dark);
BackgroundId add_local_background(const BackgroundType &type, bool is_default, bool is_dark);
void add_background(const Background &background);

View File

@ -304,11 +304,6 @@ string BackgroundType::get_link() const {
}
}
BackgroundFill BackgroundType::get_background_fill() {
CHECK(type_ == Type::Fill);
return fill_;
}
bool operator==(const BackgroundType &lhs, const BackgroundType &rhs) {
return lhs.type_ == rhs.type_ && lhs.is_blurred_ == rhs.is_blurred_ && lhs.is_moving_ == rhs.is_moving_ &&
lhs.intensity_ == rhs.intensity_ && lhs.fill_ == rhs.fill_;
@ -362,6 +357,11 @@ Result<BackgroundType> BackgroundType::get_background_type(const td_api::Backgro
}
}
Result<BackgroundType> BackgroundType::get_local_background_type(Slice name) {
TRY_RESULT(fill, BackgroundFill::get_background_fill(name));
return BackgroundType(fill);
}
BackgroundType::BackgroundType(bool is_fill, bool is_pattern,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
if (is_fill) {

View File

@ -56,7 +56,6 @@ class BackgroundFill {
friend class BackgroundType;
public:
static Result<BackgroundFill> get_background_fill(Slice name);
bool is_dark() const;
@ -76,8 +75,6 @@ class BackgroundType {
friend StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &type);
public:
BackgroundType() = default;
BackgroundType(bool is_blurred, bool is_moving)
: type_(Type::Wallpaper), is_blurred_(is_blurred), is_moving_(is_moving) {
}
@ -87,16 +84,19 @@ class BackgroundType {
explicit BackgroundType(BackgroundFill fill) : type_(Type::Fill), fill_(fill) {
}
public:
BackgroundType() = default;
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);
static Result<BackgroundType> get_local_background_type(Slice name);
bool has_file() const {
return type_ == Type::Wallpaper || type_ == Type::Pattern;
}
BackgroundFill get_background_fill();
string get_mime_type() const;
void apply_parameters_from_link(Slice name);
@ -111,6 +111,11 @@ class BackgroundType {
telegram_api::object_ptr<telegram_api::wallPaperSettings> get_input_wallpaper_settings() const;
bool is_dark() const {
CHECK(type_ == Type::Fill);
return fill_.is_dark();
}
template <class StorerT>
void store(StorerT &storer) const;