Make ThemeSettings fields private.
This commit is contained in:
parent
91a0c1acf7
commit
5ae0c78b89
@ -450,10 +450,10 @@ void ThemeManager::on_update_theme(telegram_api::object_ptr<telegram_api::theme>
|
||||
if (chat_theme.id == theme->id_) {
|
||||
for (auto &settings : theme->settings_) {
|
||||
ThemeSettings theme_settings(td_, std::move(settings));
|
||||
if (theme_settings.message_colors.empty()) {
|
||||
if (theme_settings.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
if (is_dark_base_theme(theme_settings.base_theme)) {
|
||||
if (theme_settings.are_dark()) {
|
||||
if (!was_dark) {
|
||||
was_dark = true;
|
||||
if (chat_theme.dark_theme != theme_settings) {
|
||||
@ -777,10 +777,10 @@ void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_a
|
||||
chat_theme.id = theme->id_;
|
||||
for (auto &settings : theme->settings_) {
|
||||
ThemeSettings theme_settings(td_, std::move(settings));
|
||||
if (theme_settings.message_colors.empty()) {
|
||||
if (theme_settings.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
if (is_dark_base_theme(theme_settings.base_theme)) {
|
||||
if (theme_settings.are_dark()) {
|
||||
if (!was_dark) {
|
||||
was_dark = true;
|
||||
if (chat_theme.dark_theme != theme_settings) {
|
||||
|
@ -10,37 +10,37 @@ namespace td {
|
||||
|
||||
ThemeSettings::ThemeSettings(Td *td, telegram_api::object_ptr<telegram_api::themeSettings> settings) {
|
||||
if (settings != nullptr && !settings->message_colors_.empty() && settings->message_colors_.size() <= 4) {
|
||||
accent_color = settings->accent_color_;
|
||||
accent_color_ = settings->accent_color_;
|
||||
bool has_outbox_accent_color = (settings->flags_ & telegram_api::themeSettings::OUTBOX_ACCENT_COLOR_MASK) != 0;
|
||||
message_accent_color = (has_outbox_accent_color ? settings->outbox_accent_color_ : accent_color);
|
||||
background_info = BackgroundInfo(td, std::move(settings->wallpaper_), true);
|
||||
base_theme = get_base_theme(settings->base_theme_);
|
||||
message_colors = std::move(settings->message_colors_);
|
||||
animate_message_colors = settings->message_colors_animated_;
|
||||
message_accent_color_ = (has_outbox_accent_color ? settings->outbox_accent_color_ : accent_color_);
|
||||
background_info_ = BackgroundInfo(td, std::move(settings->wallpaper_), true);
|
||||
base_theme_ = get_base_theme(settings->base_theme_);
|
||||
message_colors_ = std::move(settings->message_colors_);
|
||||
animate_message_colors_ = settings->message_colors_animated_;
|
||||
}
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::themeSettings> ThemeSettings::get_theme_settings_object(Td *td) const {
|
||||
auto fill = [&]() -> td_api::object_ptr<td_api::BackgroundFill> {
|
||||
if (message_colors.size() >= 3) {
|
||||
return td_api::make_object<td_api::backgroundFillFreeformGradient>(vector<int32>(message_colors));
|
||||
if (message_colors_.size() >= 3) {
|
||||
return td_api::make_object<td_api::backgroundFillFreeformGradient>(vector<int32>(message_colors_));
|
||||
}
|
||||
CHECK(!message_colors.empty());
|
||||
if (message_colors.size() == 1 || message_colors[0] == message_colors[1]) {
|
||||
return td_api::make_object<td_api::backgroundFillSolid>(message_colors[0]);
|
||||
CHECK(!message_colors_.empty());
|
||||
if (message_colors_.size() == 1 || message_colors_[0] == message_colors_[1]) {
|
||||
return td_api::make_object<td_api::backgroundFillSolid>(message_colors_[0]);
|
||||
}
|
||||
return td_api::make_object<td_api::backgroundFillGradient>(message_colors[1], message_colors[0], 0);
|
||||
return td_api::make_object<td_api::backgroundFillGradient>(message_colors_[1], message_colors_[0], 0);
|
||||
}();
|
||||
|
||||
// ignore base_theme for now
|
||||
return td_api::make_object<td_api::themeSettings>(accent_color, background_info.get_background_object(td),
|
||||
std::move(fill), animate_message_colors, message_accent_color);
|
||||
// ignore base_theme_ for now
|
||||
return td_api::make_object<td_api::themeSettings>(accent_color_, background_info_.get_background_object(td),
|
||||
std::move(fill), animate_message_colors_, message_accent_color_);
|
||||
}
|
||||
|
||||
bool operator==(const ThemeSettings &lhs, const ThemeSettings &rhs) {
|
||||
return lhs.accent_color == rhs.accent_color && lhs.message_accent_color == rhs.message_accent_color &&
|
||||
lhs.background_info == rhs.background_info && lhs.base_theme == rhs.base_theme &&
|
||||
lhs.message_colors == rhs.message_colors && lhs.animate_message_colors == rhs.animate_message_colors;
|
||||
return lhs.accent_color_ == rhs.accent_color_ && lhs.message_accent_color_ == rhs.message_accent_color_ &&
|
||||
lhs.background_info_ == rhs.background_info_ && lhs.base_theme_ == rhs.base_theme_ &&
|
||||
lhs.message_colors_ == rhs.message_colors_ && lhs.animate_message_colors_ == rhs.animate_message_colors_;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -17,14 +17,17 @@ namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
struct ThemeSettings {
|
||||
int32 accent_color = 0;
|
||||
int32 message_accent_color = 0;
|
||||
BackgroundInfo background_info;
|
||||
BaseTheme base_theme = BaseTheme::Classic;
|
||||
vector<int32> message_colors;
|
||||
bool animate_message_colors = false;
|
||||
class ThemeSettings {
|
||||
int32 accent_color_ = 0;
|
||||
int32 message_accent_color_ = 0;
|
||||
BackgroundInfo background_info_;
|
||||
BaseTheme base_theme_ = BaseTheme::Classic;
|
||||
vector<int32> message_colors_;
|
||||
bool animate_message_colors_ = false;
|
||||
|
||||
friend bool operator==(const ThemeSettings &lhs, const ThemeSettings &rhs);
|
||||
|
||||
public:
|
||||
ThemeSettings() = default;
|
||||
|
||||
ThemeSettings(Td *td, telegram_api::object_ptr<telegram_api::themeSettings> settings);
|
||||
@ -32,7 +35,11 @@ struct ThemeSettings {
|
||||
td_api::object_ptr<td_api::themeSettings> get_theme_settings_object(Td *td) const;
|
||||
|
||||
bool is_empty() const {
|
||||
return message_colors.empty();
|
||||
return message_colors_.empty();
|
||||
}
|
||||
|
||||
bool are_dark() const {
|
||||
return is_dark_base_theme(base_theme_);
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
|
@ -16,22 +16,22 @@ namespace td {
|
||||
|
||||
template <class StorerT>
|
||||
void ThemeSettings::store(StorerT &storer) const {
|
||||
bool has_message_accent_color = message_accent_color != accent_color;
|
||||
bool has_background = background_info.is_valid();
|
||||
bool has_message_accent_color = message_accent_color_ != accent_color_;
|
||||
bool has_background = background_info_.is_valid();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(animate_message_colors);
|
||||
STORE_FLAG(animate_message_colors_);
|
||||
STORE_FLAG(has_message_accent_color);
|
||||
STORE_FLAG(has_background);
|
||||
END_STORE_FLAGS();
|
||||
td::store(accent_color, storer);
|
||||
td::store(accent_color_, storer);
|
||||
if (has_message_accent_color) {
|
||||
td::store(message_accent_color, storer);
|
||||
td::store(message_accent_color_, storer);
|
||||
}
|
||||
if (has_background) {
|
||||
td::store(background_info, storer);
|
||||
td::store(background_info_, storer);
|
||||
}
|
||||
td::store(base_theme, storer);
|
||||
td::store(message_colors, storer);
|
||||
td::store(base_theme_, storer);
|
||||
td::store(message_colors_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
@ -39,21 +39,21 @@ void ThemeSettings::parse(ParserT &parser) {
|
||||
bool has_message_accent_color;
|
||||
bool has_background;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(animate_message_colors);
|
||||
PARSE_FLAG(animate_message_colors_);
|
||||
PARSE_FLAG(has_message_accent_color);
|
||||
PARSE_FLAG(has_background);
|
||||
END_PARSE_FLAGS();
|
||||
td::parse(accent_color, parser);
|
||||
td::parse(accent_color_, parser);
|
||||
if (has_message_accent_color) {
|
||||
td::parse(message_accent_color, parser);
|
||||
td::parse(message_accent_color_, parser);
|
||||
} else {
|
||||
message_accent_color = accent_color;
|
||||
message_accent_color_ = accent_color_;
|
||||
}
|
||||
if (has_background) {
|
||||
td::parse(background_info, parser);
|
||||
td::parse(background_info_, parser);
|
||||
}
|
||||
td::parse(base_theme, parser);
|
||||
td::parse(message_colors, parser);
|
||||
td::parse(base_theme_, parser);
|
||||
td::parse(message_colors_, parser);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user