2021-08-27 15:51:50 +03:00
|
|
|
//
|
2024-01-01 03:07:21 +03:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2021-08-27 15:51:50 +03: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 14:21:55 +03:00
|
|
|
#include "td/telegram/AccentColorId.h"
|
2023-04-10 16:32:59 +03:00
|
|
|
#include "td/telegram/BackgroundInfo.h"
|
2021-09-01 20:31:39 +03:00
|
|
|
#include "td/telegram/td_api.h"
|
2021-08-27 15:51:50 +03:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2023-11-02 14:21:55 +03:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-06-27 13:30:18 +03:00
|
|
|
#include "td/utils/Promise.h"
|
2021-08-27 15:51:50 +03:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class ThemeManager final : public Actor {
|
|
|
|
public:
|
|
|
|
ThemeManager(Td *td, ActorShared<> parent);
|
|
|
|
|
2021-09-13 15:55:01 +03:00
|
|
|
void init();
|
2021-08-27 15:51:50 +03:00
|
|
|
|
2021-09-12 22:29:40 +03:00
|
|
|
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
|
|
|
|
|
2023-11-27 13:34:14 +03:00
|
|
|
void reload_chat_themes();
|
|
|
|
|
2023-11-27 16:35:27 +03:00
|
|
|
void reload_accent_colors();
|
2023-11-02 14:21:55 +03:00
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
void reload_profile_accent_colors();
|
|
|
|
|
2022-03-29 20:22:38 +03:00
|
|
|
static string get_theme_parameters_json_string(const td_api::object_ptr<td_api::themeParameters> &theme,
|
|
|
|
bool for_web_view);
|
|
|
|
|
2023-11-02 22:32:59 +03:00
|
|
|
int32 get_accent_color_id_object(AccentColorId accent_color_id,
|
|
|
|
AccentColorId fallback_accent_color_id = AccentColorId()) const;
|
2023-11-02 22:11:54 +03:00
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
int32 get_profile_accent_color_id_object(AccentColorId accent_color_id) const;
|
|
|
|
|
2023-12-26 20:20:41 +03:00
|
|
|
struct DialogBoostAvailableCounts {
|
|
|
|
int32 title_color_count_ = 0;
|
|
|
|
int32 accent_color_count_ = 0;
|
|
|
|
int32 profile_accent_color_count_ = 0;
|
|
|
|
int32 chat_theme_count_ = 0;
|
|
|
|
};
|
2024-02-08 14:35:42 +03:00
|
|
|
DialogBoostAvailableCounts get_dialog_boost_available_count(int32 level, bool for_megagroup);
|
2023-12-26 20:20:41 +03:00
|
|
|
|
2021-09-13 15:55:01 +03:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2021-08-27 15:51:50 +03:00
|
|
|
private:
|
2024-03-26 00:03:39 +03:00
|
|
|
// append-only
|
2021-08-27 15:51:50 +03:00
|
|
|
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
|
|
|
|
|
|
|
|
struct ThemeSettings {
|
|
|
|
int32 accent_color = 0;
|
2021-09-07 22:04:44 +03:00
|
|
|
int32 message_accent_color = 0;
|
2023-04-10 16:32:59 +03:00
|
|
|
BackgroundInfo background_info;
|
2021-11-11 17:39:09 +03:00
|
|
|
BaseTheme base_theme = BaseTheme::Classic;
|
2021-08-27 15:51:50 +03:00
|
|
|
vector<int32> message_colors;
|
|
|
|
bool animate_message_colors = false;
|
2021-09-24 17:17:32 +03:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2021-08-27 15:51:50 +03:00
|
|
|
};
|
|
|
|
|
2021-09-12 22:39:52 +03:00
|
|
|
friend bool operator==(const ThemeSettings &lhs, const ThemeSettings &rhs);
|
|
|
|
|
|
|
|
friend bool operator!=(const ThemeSettings &lhs, const ThemeSettings &rhs);
|
|
|
|
|
2021-08-27 15:51:50 +03:00
|
|
|
struct ChatTheme {
|
|
|
|
string emoji;
|
2021-10-08 13:45:10 +03:00
|
|
|
int64 id = 0;
|
2021-08-27 15:51:50 +03:00
|
|
|
ThemeSettings light_theme;
|
|
|
|
ThemeSettings dark_theme;
|
2021-09-24 17:17:32 +03:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2021-08-27 15:51:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ChatThemes {
|
2021-10-08 13:45:10 +03:00
|
|
|
int64 hash = 0;
|
2021-08-27 15:51:50 +03:00
|
|
|
vector<ChatTheme> themes;
|
2021-09-24 17:17:32 +03:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2021-08-27 15:51:50 +03:00
|
|
|
};
|
|
|
|
|
2023-11-02 14:21:55 +03:00
|
|
|
struct AccentColors {
|
|
|
|
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors_;
|
|
|
|
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors_;
|
|
|
|
vector<AccentColorId> accent_color_ids_;
|
2024-02-08 14:35:42 +03:00
|
|
|
vector<int32> min_broadcast_boost_levels_;
|
|
|
|
vector<int32> min_megagroup_boost_levels_;
|
2023-11-27 16:35:27 +03:00
|
|
|
int32 hash_ = 0;
|
2023-11-02 21:30:38 +03:00
|
|
|
|
|
|
|
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
|
2023-11-02 21:52:59 +03:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2023-11-02 14:21:55 +03:00
|
|
|
};
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
struct ProfileAccentColor {
|
|
|
|
vector<int32> palette_colors_;
|
|
|
|
vector<int32> background_colors_;
|
|
|
|
vector<int32> story_colors_;
|
|
|
|
|
2023-11-27 18:40:02 +03:00
|
|
|
bool is_valid() const;
|
|
|
|
|
2023-11-27 18:08:45 +03: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_;
|
2024-02-08 14:35:42 +03:00
|
|
|
vector<int32> min_broadcast_boost_levels_;
|
|
|
|
vector<int32> min_megagroup_boost_levels_;
|
2023-11-27 18:08:45 +03: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);
|
|
|
|
};
|
|
|
|
|
2023-11-07 00:17:49 +03:00
|
|
|
void start_up() final;
|
|
|
|
|
2021-08-27 15:51:50 +03:00
|
|
|
void tear_down() final;
|
|
|
|
|
2023-11-07 00:17:49 +03:00
|
|
|
void load_chat_themes();
|
|
|
|
|
|
|
|
void load_accent_colors();
|
2023-11-03 16:02:28 +03:00
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
void load_profile_accent_colors();
|
|
|
|
|
2021-10-08 13:45:10 +03: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 15:51:50 +03:00
|
|
|
|
2023-11-27 16:35:27 +03:00
|
|
|
bool on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
|
|
|
|
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
|
2024-02-08 14:35:42 +03:00
|
|
|
vector<AccentColorId> accent_color_ids, vector<int32> min_broadcast_boost_levels,
|
|
|
|
vector<int32> min_megagroup_boost_levels);
|
2023-11-27 16:35:27 +03:00
|
|
|
|
|
|
|
void on_get_accent_colors(Result<telegram_api::object_ptr<telegram_api::help_PeerColors>> result);
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
bool on_update_profile_accent_colors(FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors,
|
|
|
|
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors,
|
2024-02-08 14:35:42 +03:00
|
|
|
vector<AccentColorId> accent_color_ids, vector<int32> min_broadcast_boost_levels,
|
|
|
|
vector<int32> min_megagroup_boost_levels);
|
2023-11-27 18:08:45 +03: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 15:51:50 +03: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;
|
|
|
|
|
2021-09-13 15:55:01 +03:00
|
|
|
td_api::object_ptr<td_api::updateChatThemes> get_update_chat_themes_object() const;
|
|
|
|
|
2021-09-24 17:17:32 +03:00
|
|
|
static string get_chat_themes_database_key();
|
|
|
|
|
2023-11-02 21:52:59 +03:00
|
|
|
string get_accent_colors_database_key();
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
string get_profile_accent_colors_database_key();
|
|
|
|
|
2021-09-24 17:17:32 +03:00
|
|
|
void save_chat_themes();
|
|
|
|
|
2023-11-02 21:52:59 +03:00
|
|
|
void save_accent_colors();
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
void save_profile_accent_colors();
|
|
|
|
|
2021-09-13 15:55:01 +03:00
|
|
|
void send_update_chat_themes() const;
|
2021-09-03 08:59:34 +03:00
|
|
|
|
2021-08-27 15:51:50 +03: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 21:30:38 +03:00
|
|
|
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
|
|
|
|
|
2023-11-02 21:30:38 +03:00
|
|
|
void send_update_accent_colors() const;
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
void send_update_profile_accent_colors() const;
|
|
|
|
|
2021-08-27 15:51:50 +03:00
|
|
|
ChatThemes chat_themes_;
|
|
|
|
|
2023-11-02 14:21:55 +03:00
|
|
|
AccentColors accent_colors_;
|
|
|
|
|
2023-11-27 18:08:45 +03:00
|
|
|
ProfileAccentColors profile_accent_colors_;
|
|
|
|
|
2021-08-27 15:51:50 +03:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|