Reload chat themes with other data.

This commit is contained in:
levlam 2023-11-27 13:34:14 +03:00
parent bf9c8c81c7
commit d08796fade
3 changed files with 12 additions and 27 deletions

View File

@ -204,7 +204,6 @@ void ThemeManager::load_chat_themes() { // must not be called in constructor, b
chat_themes_ = ChatThemes();
}
}
chat_themes_.next_reload_time = Time::now();
}
void ThemeManager::load_accent_colors() {
@ -233,23 +232,6 @@ void ThemeManager::tear_down() {
parent_.reset();
}
void ThemeManager::loop() {
if (!td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) {
return;
}
if (Time::now() < chat_themes_.next_reload_time) {
return set_timeout_at(chat_themes_.next_reload_time);
}
auto request_promise = PromiseCreator::lambda(
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::account_Themes>> result) {
send_closure(actor_id, &ThemeManager::on_get_chat_themes, std::move(result));
});
td_->create_handler<GetChatThemesQuery>(std::move(request_promise))->send(chat_themes_.hash);
}
bool ThemeManager::is_dark_base_theme(BaseTheme base_theme) {
switch (base_theme) {
case BaseTheme::Classic:
@ -491,15 +473,20 @@ void ThemeManager::send_update_accent_colors() const {
send_closure(G()->td(), &Td::send_update, get_update_accent_colors_object());
}
void ThemeManager::reload_chat_themes() {
auto request_promise = PromiseCreator::lambda(
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::account_Themes>> result) {
send_closure(actor_id, &ThemeManager::on_get_chat_themes, std::move(result));
});
td_->create_handler<GetChatThemesQuery>(std::move(request_promise))->send(chat_themes_.hash);
}
void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_api::account_Themes>> result) {
if (result.is_error()) {
set_timeout_in(Random::fast(40, 60));
return;
}
chat_themes_.next_reload_time = Time::now() + THEME_CACHE_TIME;
set_timeout_at(chat_themes_.next_reload_time);
auto chat_themes_ptr = result.move_as_ok();
LOG(DEBUG) << "Receive " << to_string(chat_themes_ptr);
if (chat_themes_ptr->get_id() == telegram_api::account_themesNotModified::ID) {

View File

@ -30,6 +30,8 @@ class ThemeManager final : public Actor {
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
void reload_chat_themes();
void on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids);
@ -46,8 +48,6 @@ class ThemeManager final : public Actor {
// apeend-only
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
static constexpr int32 THEME_CACHE_TIME = 3600;
struct ThemeSettings {
int32 accent_color = 0;
int32 message_accent_color = 0;
@ -82,7 +82,6 @@ class ThemeManager final : public Actor {
struct ChatThemes {
int64 hash = 0;
double next_reload_time = 0;
vector<ChatTheme> themes;
template <class StorerT>
@ -108,8 +107,6 @@ class ThemeManager final : public Actor {
void start_up() final;
void loop() final;
void tear_down() final;
void load_chat_themes();

View File

@ -2261,6 +2261,7 @@ void UpdatesManager::try_reload_data() {
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::UserProfilePhoto, true, Auto());
td_->story_manager_->reload_active_stories();
td_->story_manager_->reload_all_read_stories();
td_->theme_manager_->reload_chat_themes();
schedule_data_reload();
}