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
|
|
|
|
|
|
|
|
#include "td/telegram/BackgroundId.h"
|
|
|
|
#include "td/telegram/BackgroundType.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"
|
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);
|
|
|
|
|
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);
|
|
|
|
|
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;
|
2021-08-27 14:51:50 +02:00
|
|
|
BackgroundId background_id;
|
|
|
|
BackgroundType background_type;
|
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
|
|
|
};
|
|
|
|
|
2021-09-13 14:55:01 +02:00
|
|
|
void start_up() final;
|
|
|
|
|
|
|
|
void loop() final;
|
|
|
|
|
2021-08-27 14:51:50 +02:00
|
|
|
void tear_down() final;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
void save_chat_themes();
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ChatThemes chat_themes_;
|
|
|
|
|
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|