Update chat theme cache after receiving telegram_api::updateTheme.
This commit is contained in:
parent
488e5699b7
commit
196128b2f1
|
@ -73,6 +73,24 @@ void ThemeManager::get_chat_themes(Promise<td_api::object_ptr<td_api::chatThemes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeManager::on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise) {
|
||||||
|
CHECK(theme != nullptr);
|
||||||
|
for (auto &chat_theme : chat_themes_.themes) {
|
||||||
|
if (chat_theme.light_id == theme->id_ || chat_theme.dark_id == theme->id_) {
|
||||||
|
chat_themes_.hash = 0;
|
||||||
|
chat_themes_.next_reload_time = Time::now();
|
||||||
|
auto theme_settings = get_chat_theme_settings(std::move(theme->settings_));
|
||||||
|
if (chat_theme.light_id == theme->id_) {
|
||||||
|
chat_theme.light_theme = theme_settings;
|
||||||
|
}
|
||||||
|
if (chat_theme.dark_id == theme->id_) {
|
||||||
|
chat_theme.dark_theme = theme_settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::themeSettings> ThemeManager::get_theme_settings_object(const ThemeSettings &settings) const {
|
td_api::object_ptr<td_api::themeSettings> ThemeManager::get_theme_settings_object(const ThemeSettings &settings) const {
|
||||||
auto fill = [colors = settings.message_colors]() mutable -> td_api::object_ptr<td_api::BackgroundFill> {
|
auto fill = [colors = settings.message_colors]() mutable -> td_api::object_ptr<td_api::BackgroundFill> {
|
||||||
if (colors.size() >= 3) {
|
if (colors.size() >= 3) {
|
||||||
|
@ -134,6 +152,8 @@ void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_a
|
||||||
|
|
||||||
ChatTheme theme;
|
ChatTheme theme;
|
||||||
theme.emoji = std::move(chat_theme->emoticon_);
|
theme.emoji = std::move(chat_theme->emoticon_);
|
||||||
|
theme.light_id = chat_theme->theme_->id_;
|
||||||
|
theme.dark_id = chat_theme->dark_theme_->id_;
|
||||||
theme.light_theme = get_chat_theme_settings(std::move(chat_theme->theme_->settings_));
|
theme.light_theme = get_chat_theme_settings(std::move(chat_theme->theme_->settings_));
|
||||||
theme.dark_theme = get_chat_theme_settings(std::move(chat_theme->dark_theme_->settings_));
|
theme.dark_theme = get_chat_theme_settings(std::move(chat_theme->dark_theme_->settings_));
|
||||||
chat_themes_.themes.push_back(std::move(theme));
|
chat_themes_.themes.push_back(std::move(theme));
|
||||||
|
|
|
@ -27,6 +27,8 @@ class ThemeManager final : public Actor {
|
||||||
|
|
||||||
void get_chat_themes(Promise<td_api::object_ptr<td_api::chatThemes>> &&promise);
|
void get_chat_themes(Promise<td_api::object_ptr<td_api::chatThemes>> &&promise);
|
||||||
|
|
||||||
|
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
|
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
|
||||||
|
|
||||||
|
@ -43,6 +45,8 @@ class ThemeManager final : public Actor {
|
||||||
|
|
||||||
struct ChatTheme {
|
struct ChatTheme {
|
||||||
string emoji;
|
string emoji;
|
||||||
|
int64 light_id = 0;
|
||||||
|
int64 dark_id = 0;
|
||||||
ThemeSettings light_theme;
|
ThemeSettings light_theme;
|
||||||
ThemeSettings dark_theme;
|
ThemeSettings dark_theme;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "td/telegram/StickersManager.h"
|
#include "td/telegram/StickersManager.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/TdDb.h"
|
#include "td/telegram/TdDb.h"
|
||||||
|
#include "td/telegram/ThemeManager.h"
|
||||||
#include "td/telegram/WebPagesManager.h"
|
#include "td/telegram/WebPagesManager.h"
|
||||||
|
|
||||||
#include "td/actor/MultiPromise.h"
|
#include "td/actor/MultiPromise.h"
|
||||||
|
@ -3206,10 +3207,10 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticip
|
||||||
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
add_pending_qts_update(std::move(update), qts, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsupported updates
|
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise) {
|
||||||
promise.set_value(Unit());
|
td_->theme_manager_->on_update_theme(std::move(update->theme_), std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unsupported updates
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
|
@ -486,9 +486,9 @@ class UpdatesManager final : public Actor {
|
||||||
void on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateChatParticipant> update, Promise<Unit> &&promise);
|
||||||
void on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateChannelParticipant> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
// unsupported updates
|
|
||||||
|
|
||||||
void on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise);
|
void on_update(tl_object_ptr<telegram_api::updateTheme> update, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
// unsupported updates
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
Loading…
Reference in New Issue
Block a user