diff options
| author | levlam <levlam@telegram.org> | 2025-09-17 01:20:06 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-09-17 01:20:06 +0300 |
| commit | 4f21561fdeb36472caf529c4f0495310327ce26b (patch) | |
| tree | 4e120e3fb9b8e1a3a85d3aeac31cc95e6a4d0b53 /td/telegram/ThemeManager.cpp | |
| parent | 181a87a62cd4de6deb9359abf695952913984fde (diff) | |
Add td_api::getGiftChatThemes.
Diffstat (limited to 'td/telegram/ThemeManager.cpp')
| -rw-r--r-- | td/telegram/ThemeManager.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp index d30f1892d..cef955d87 100644 --- a/td/telegram/ThemeManager.cpp +++ b/td/telegram/ThemeManager.cpp @@ -7,6 +7,8 @@ #include "td/telegram/ThemeManager.h" #include "td/telegram/AuthManager.h" +#include "td/telegram/ChatManager.h" +#include "td/telegram/ChatTheme.h" #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/net/NetQueryCreator.h" @@ -15,6 +17,7 @@ #include "td/telegram/TdDb.h" #include "td/telegram/telegram_api.h" #include "td/telegram/ThemeSettings.hpp" +#include "td/telegram/UserManager.h" #include "td/utils/algorithm.h" #include "td/utils/buffer.h" @@ -116,6 +119,59 @@ class GetPeerProfileColorsQuery final : public Td::ResultHandler { } }; +class GetUniqueGiftChatThemesQuery final : public Td::ResultHandler { + Promise<td_api::object_ptr<td_api::giftChatThemes>> promise_; + + public: + explicit GetUniqueGiftChatThemesQuery(Promise<td_api::object_ptr<td_api::giftChatThemes>> &&promise) + : promise_(std::move(promise)) { + } + + void send(const string &offset, int32 limit) { + send_query(G()->net_query_creator().create( + telegram_api::account_getUniqueGiftChatThemes(to_integer<int32>(offset), limit, 0))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result<telegram_api::account_getUniqueGiftChatThemes>(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for GetUniqueGiftChatThemesQuery: " << to_string(ptr); + switch (ptr->get_id()) { + case telegram_api::account_chatThemesNotModified::ID: + LOG(ERROR) << "Receive " << to_string(ptr); + return on_error(Status::Error(500, "Receive wrong server response")); + case telegram_api::account_chatThemes::ID: { + auto themes = telegram_api::move_object_as<telegram_api::account_chatThemes>(ptr); + td_->user_manager_->on_get_users(std::move(themes->users_), "GetUniqueGiftChatThemesQuery"); + td_->chat_manager_->on_get_chats(std::move(themes->chats_), "GetUniqueGiftChatThemesQuery"); + auto result = td_api::make_object<td_api::giftChatThemes>(); + if (themes->next_offset_ != 0) { + result->next_offset_ = to_string(themes->next_offset_); + } + for (auto &theme : themes->themes_) { + ChatTheme chat_theme(td_, std::move(theme)); + if (!chat_theme.is_gift()) { + LOG(ERROR) << "Receive " << chat_theme; + continue; + } + result->themes_.push_back(chat_theme.get_gift_chat_theme_object(td_)); + } + return promise_.set_value(std::move(result)); + } + default: + UNREACHABLE(); + } + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + bool operator==(const ThemeManager::ProfileAccentColor &lhs, const ThemeManager::ProfileAccentColor &rhs) { return lhs.palette_colors_ == rhs.palette_colors_ && lhs.background_colors_ == rhs.background_colors_ && lhs.story_colors_ == rhs.story_colors_; @@ -968,6 +1024,11 @@ void ThemeManager::on_get_profile_accent_colors( } } +void ThemeManager::get_unique_gift_chat_themes(const string &offset, int32 limit, + Promise<td_api::object_ptr<td_api::giftChatThemes>> &&promise) { + td_->create_handler<GetUniqueGiftChatThemesQuery>(std::move(promise))->send(offset, limit); +} + void ThemeManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const { if (!td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) { return; |
