tdlight/td/telegram/ThemeManager.h

228 lines
6.8 KiB
C
Raw Normal View History

2021-08-27 14:51:50 +02:00
//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
2021-08-27 14:51:50 +02:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
2023-11-02 12:21:55 +01:00
#include "td/telegram/AccentColorId.h"
2023-04-10 15:32:59 +02:00
#include "td/telegram/BackgroundInfo.h"
2021-09-01 19:31:39 +02:00
#include "td/telegram/td_api.h"
2021-08-27 14:51:50 +02:00
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/utils/common.h"
2023-11-02 12:21:55 +01:00
#include "td/utils/FlatHashMap.h"
2022-06-27 12:30:18 +02:00
#include "td/utils/Promise.h"
2021-08-27 14:51:50 +02:00
#include "td/utils/Status.h"
namespace td {
class Td;
class ThemeManager final : public Actor {
public:
ThemeManager(Td *td, ActorShared<> parent);
void init();
2021-08-27 14:51:50 +02:00
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
2023-11-27 11:34:14 +01:00
void reload_chat_themes();
void reload_accent_colors();
2023-11-02 12:21:55 +01:00
2023-11-27 16:08:45 +01:00
void reload_profile_accent_colors();
static string get_theme_parameters_json_string(const td_api::object_ptr<td_api::themeParameters> &theme,
bool for_web_view);
int32 get_accent_color_id_object(AccentColorId accent_color_id,
AccentColorId fallback_accent_color_id = AccentColorId()) const;
2023-11-27 16:08:45 +01:00
int32 get_profile_accent_color_id_object(AccentColorId accent_color_id) const;
2023-12-26 18:20:41 +01:00
struct DialogBoostAvailableCounts {
int32 title_color_count_ = 0;
int32 accent_color_count_ = 0;
int32 profile_accent_color_count_ = 0;
int32 chat_theme_count_ = 0;
};
DialogBoostAvailableCounts get_dialog_boost_available_count(int32 level);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
2021-08-27 14:51:50 +02:00
private:
2021-09-24 16:17:32 +02:00
// apeend-only
2021-08-27 14:51:50 +02:00
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
struct ThemeSettings {
int32 accent_color = 0;
int32 message_accent_color = 0;
2023-04-10 15:32:59 +02:00
BackgroundInfo background_info;
2021-11-11 15:39:09 +01:00
BaseTheme base_theme = BaseTheme::Classic;
2021-08-27 14:51:50 +02:00
vector<int32> message_colors;
bool animate_message_colors = false;
2021-09-24 16:17:32 +02:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2021-08-27 14:51:50 +02:00
};
2021-09-12 21:39:52 +02:00
friend bool operator==(const ThemeSettings &lhs, const ThemeSettings &rhs);
friend bool operator!=(const ThemeSettings &lhs, const ThemeSettings &rhs);
2021-08-27 14:51:50 +02:00
struct ChatTheme {
string emoji;
2021-10-08 12:45:10 +02:00
int64 id = 0;
2021-08-27 14:51:50 +02:00
ThemeSettings light_theme;
ThemeSettings dark_theme;
2021-09-24 16:17:32 +02:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2021-08-27 14:51:50 +02:00
};
struct ChatThemes {
2021-10-08 12:45:10 +02:00
int64 hash = 0;
2021-08-27 14:51:50 +02:00
vector<ChatTheme> themes;
2021-09-24 16:17:32 +02:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2021-08-27 14:51:50 +02:00
};
2023-11-02 12:21:55 +01:00
struct AccentColors {
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_boost_levels_;
int32 hash_ = 0;
2023-11-02 19:30:38 +01:00
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
2023-11-02 19:52:59 +01:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2023-11-02 12:21:55 +01:00
};
2023-11-27 16:08:45 +01:00
struct ProfileAccentColor {
vector<int32> palette_colors_;
vector<int32> background_colors_;
vector<int32> story_colors_;
2023-11-27 16:40:02 +01:00
bool is_valid() const;
2023-11-27 16:08:45 +01:00
td_api::object_ptr<td_api::profileAccentColors> get_profile_accent_colors_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
friend bool operator==(const ProfileAccentColor &lhs, const ProfileAccentColor &rhs);
friend bool operator!=(const ProfileAccentColor &lhs, const ProfileAccentColor &rhs);
struct ProfileAccentColors {
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_boost_levels_;
2023-11-27 16:08:45 +01:00
int32 hash_ = 0;
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
void start_up() final;
2021-08-27 14:51:50 +02:00
void tear_down() final;
void load_chat_themes();
void load_accent_colors();
2023-11-03 14:02:28 +01:00
2023-11-27 16:08:45 +01:00
void load_profile_accent_colors();
2021-10-08 12:45:10 +02:00
static bool is_dark_base_theme(BaseTheme base_theme);
void on_get_chat_themes(Result<telegram_api::object_ptr<telegram_api::account_Themes>> result);
2021-08-27 14:51:50 +02:00
bool on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids, vector<int32> min_boost_levels);
void on_get_accent_colors(Result<telegram_api::object_ptr<telegram_api::help_PeerColors>> result);
2023-11-27 16:08:45 +01:00
bool on_update_profile_accent_colors(FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids, vector<int32> min_boost_levels);
2023-11-27 16:08:45 +01:00
ProfileAccentColor get_profile_accent_color(
telegram_api::object_ptr<telegram_api::help_PeerColorSet> &&color_set) const;
void on_get_profile_accent_colors(Result<telegram_api::object_ptr<telegram_api::help_PeerColors>> result);
2021-08-27 14:51:50 +02:00
td_api::object_ptr<td_api::themeSettings> get_theme_settings_object(const ThemeSettings &settings) const;
td_api::object_ptr<td_api::chatTheme> get_chat_theme_object(const ChatTheme &theme) const;
td_api::object_ptr<td_api::updateChatThemes> get_update_chat_themes_object() const;
2021-09-24 16:17:32 +02:00
static string get_chat_themes_database_key();
2023-11-02 19:52:59 +01:00
string get_accent_colors_database_key();
2023-11-27 16:08:45 +01:00
string get_profile_accent_colors_database_key();
2021-09-24 16:17:32 +02:00
void save_chat_themes();
2023-11-02 19:52:59 +01:00
void save_accent_colors();
2023-11-27 16:08:45 +01:00
void save_profile_accent_colors();
void send_update_chat_themes() const;
2021-08-27 14:51:50 +02:00
static BaseTheme get_base_theme(const telegram_api::object_ptr<telegram_api::BaseTheme> &base_theme);
ThemeSettings get_chat_theme_settings(telegram_api::object_ptr<telegram_api::themeSettings> settings);
2023-11-02 19:30:38 +01:00
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
2023-11-27 16:08:45 +01:00
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
2023-11-02 19:30:38 +01:00
void send_update_accent_colors() const;
2023-11-27 16:08:45 +01:00
void send_update_profile_accent_colors() const;
2021-08-27 14:51:50 +02:00
ChatThemes chat_themes_;
2023-11-02 12:21:55 +01:00
AccentColors accent_colors_;
2023-11-27 16:08:45 +01:00
ProfileAccentColors profile_accent_colors_;
2021-08-27 14:51:50 +02:00
Td *td_;
ActorShared<> parent_;
};
} // namespace td