// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 // // 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 #include "td/telegram/AccentColorId.h" #include "td/telegram/BackgroundInfo.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { class Td; class ThemeManager final : public Actor { public: ThemeManager(Td *td, ActorShared<> parent); void init(); void on_update_theme(telegram_api::object_ptr &&theme, Promise &&promise); void reload_chat_themes(); void reload_accent_colors(); void reload_profile_accent_colors(); static string get_theme_parameters_json_string(const td_api::object_ptr &theme, bool for_web_view); int32 get_accent_color_id_object(AccentColorId accent_color_id, AccentColorId fallback_accent_color_id = AccentColorId()) const; int32 get_profile_accent_color_id_object(AccentColorId accent_color_id) const; void get_current_state(vector> &updates) const; private: // apeend-only enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic }; struct ThemeSettings { int32 accent_color = 0; int32 message_accent_color = 0; BackgroundInfo background_info; BaseTheme base_theme = BaseTheme::Classic; vector message_colors; bool animate_message_colors = false; template void store(StorerT &storer) const; template void parse(ParserT &parser); }; friend bool operator==(const ThemeSettings &lhs, const ThemeSettings &rhs); friend bool operator!=(const ThemeSettings &lhs, const ThemeSettings &rhs); struct ChatTheme { string emoji; int64 id = 0; ThemeSettings light_theme; ThemeSettings dark_theme; template void store(StorerT &storer) const; template void parse(ParserT &parser); }; struct ChatThemes { int64 hash = 0; vector themes; template void store(StorerT &storer) const; template void parse(ParserT &parser); }; struct AccentColors { FlatHashMap, AccentColorIdHash> light_colors_; FlatHashMap, AccentColorIdHash> dark_colors_; vector accent_color_ids_; int32 hash_ = 0; td_api::object_ptr get_update_accent_colors_object() const; template void store(StorerT &storer) const; template void parse(ParserT &parser); }; struct ProfileAccentColor { vector palette_colors_; vector background_colors_; vector story_colors_; td_api::object_ptr get_profile_accent_colors_object() const; template void store(StorerT &storer) const; template 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 light_colors_; FlatHashMap dark_colors_; vector accent_color_ids_; int32 hash_ = 0; td_api::object_ptr get_update_profile_accent_colors_object() const; template void store(StorerT &storer) const; template void parse(ParserT &parser); }; void start_up() final; void tear_down() final; void load_chat_themes(); void load_accent_colors(); void load_profile_accent_colors(); static bool is_dark_base_theme(BaseTheme base_theme); void on_get_chat_themes(Result> result); bool on_update_accent_colors(FlatHashMap, AccentColorIdHash> light_colors, FlatHashMap, AccentColorIdHash> dark_colors, vector accent_color_ids); void on_get_accent_colors(Result> result); bool on_update_profile_accent_colors(FlatHashMap light_colors, FlatHashMap dark_colors, vector accent_color_ids); ProfileAccentColor get_profile_accent_color( telegram_api::object_ptr &&color_set) const; void on_get_profile_accent_colors(Result> result); td_api::object_ptr get_theme_settings_object(const ThemeSettings &settings) const; td_api::object_ptr get_chat_theme_object(const ChatTheme &theme) const; td_api::object_ptr get_update_chat_themes_object() const; static string get_chat_themes_database_key(); string get_accent_colors_database_key(); string get_profile_accent_colors_database_key(); void save_chat_themes(); void save_accent_colors(); void save_profile_accent_colors(); void send_update_chat_themes() const; static BaseTheme get_base_theme(const telegram_api::object_ptr &base_theme); ThemeSettings get_chat_theme_settings(telegram_api::object_ptr settings); td_api::object_ptr get_update_accent_colors_object() const; td_api::object_ptr get_update_profile_accent_colors_object() const; void send_update_accent_colors() const; void send_update_profile_accent_colors() const; ChatThemes chat_themes_; AccentColors accent_colors_; ProfileAccentColors profile_accent_colors_; Td *td_; ActorShared<> parent_; }; } // namespace td