2021-08-27 14:51:50 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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);
|
|
|
|
|
2021-09-13 14:55:01 +02:00
|
|
|
void init();
|
2021-08-27 14:51:50 +02:00
|
|
|
|
2021-09-12 21:29:40 +02:00
|
|
|
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
|
|
|
|
|
2023-11-02 12:21:55 +01:00
|
|
|
void on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
|
|
|
|
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
|
|
|
|
vector<AccentColorId> accent_color_ids);
|
|
|
|
|
2022-03-29 19:22:38 +02:00
|
|
|
static string get_theme_parameters_json_string(const td_api::object_ptr<td_api::themeParameters> &theme,
|
|
|
|
bool for_web_view);
|
|
|
|
|
2023-11-02 20:32:59 +01:00
|
|
|
int32 get_accent_color_id_object(AccentColorId accent_color_id,
|
|
|
|
AccentColorId fallback_accent_color_id = AccentColorId()) const;
|
2023-11-02 20:11:54 +01:00
|
|
|
|
2021-09-13 14:55:01 +02:00
|
|
|
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 };
|
|
|
|
|
2021-09-07 12:30:51 +02:00
|
|
|
static constexpr int32 THEME_CACHE_TIME = 3600;
|
|
|
|
|
2021-08-27 14:51:50 +02:00
|
|
|
struct ThemeSettings {
|
|
|
|
int32 accent_color = 0;
|
2021-09-07 21:04:44 +02:00
|
|
|
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-09-07 12:30:51 +02:00
|
|
|
double next_reload_time = 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_;
|
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
|
|
|
};
|
|
|
|
|
2021-09-13 14:55:01 +02:00
|
|
|
void loop() final;
|
|
|
|
|
2021-08-27 14:51:50 +02:00
|
|
|
void tear_down() final;
|
|
|
|
|
2023-11-03 14:02:28 +01:00
|
|
|
void do_init();
|
|
|
|
|
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
|
|
|
|
|
|
|
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 14:55:01 +02:00
|
|
|
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();
|
|
|
|
|
2021-09-24 16:17:32 +02:00
|
|
|
void save_chat_themes();
|
|
|
|
|
2023-11-02 19:52:59 +01:00
|
|
|
void save_accent_colors();
|
|
|
|
|
2021-09-13 14:55:01 +02:00
|
|
|
void send_update_chat_themes() const;
|
2021-09-03 07:59:34 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
void send_update_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_;
|
|
|
|
|
2021-08-27 14:51:50 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|