Use promise instead of RequestActor in td_api::getChatThemes.

This commit is contained in:
levlam 2021-09-03 08:59:34 +03:00
parent db4f963a68
commit d2f9c264ca
3 changed files with 9 additions and 22 deletions

View File

@ -2910,20 +2910,6 @@ class SetBackgroundRequest final : public RequestActor<> {
}
};
class GetChatThemesRequest final : public RequestOnceActor {
void do_run(Promise<Unit> &&promise) final {
td->theme_manager_->get_chat_themes(std::move(promise));
}
void do_send_result() final {
send_result(td->theme_manager_->get_chat_themes_object());
}
public:
GetChatThemesRequest(ActorShared<Td> td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) {
}
};
Td::Td(unique_ptr<TdCallback> callback, Options options)
: callback_(std::move(callback)), td_options_(std::move(options)) {
CHECK(callback_ != nullptr);
@ -8095,7 +8081,8 @@ void Td::on_request(uint64 id, const td_api::resetBackgrounds &request) {
void Td::on_request(uint64 id, const td_api::getChatThemes &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetChatThemesRequest);
CREATE_REQUEST_PROMISE();
theme_manager_->get_chat_themes(std::move(promise));
}
void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) {

View File

@ -50,7 +50,7 @@ void ThemeManager::tear_down() {
parent_.reset();
}
void ThemeManager::get_chat_themes(Promise<Unit> &&promise) {
void ThemeManager::get_chat_themes(Promise<td_api::object_ptr<td_api::chatThemes>> &&promise) {
pending_get_chat_themes_queries_.push_back(std::move(promise));
if (pending_get_chat_themes_queries_.size() == 1) {
auto request_promise = PromiseCreator::lambda(
@ -110,7 +110,7 @@ void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_a
LOG(DEBUG) << "Receive " << to_string(chat_themes_ptr);
if (chat_themes_ptr->get_id() == telegram_api::account_chatThemesNotModified::ID) {
for (auto &promise : promises) {
promise.set_value(Unit());
promise.set_value(get_chat_themes_object());
}
return;
}
@ -133,7 +133,7 @@ void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_a
}
for (auto &promise : promises) {
promise.set_value(Unit());
promise.set_value(get_chat_themes_object());
}
}

View File

@ -25,9 +25,7 @@ class ThemeManager final : public Actor {
public:
ThemeManager(Td *td, ActorShared<> parent);
void get_chat_themes(Promise<Unit> &&promise);
td_api::object_ptr<td_api::chatThemes> get_chat_themes_object() const;
void get_chat_themes(Promise<td_api::object_ptr<td_api::chatThemes>> &&promise);
private:
enum class BaseTheme : int32 { Classic, Day, Night, Tinted, Arctic };
@ -60,11 +58,13 @@ class ThemeManager final : public Actor {
td_api::object_ptr<td_api::chatTheme> get_chat_theme_object(const ChatTheme &theme) const;
td_api::object_ptr<td_api::chatThemes> get_chat_themes_object() const;
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);
vector<Promise<Unit>> pending_get_chat_themes_queries_;
vector<Promise<td_api::object_ptr<td_api::chatThemes>>> pending_get_chat_themes_queries_;
ChatThemes chat_themes_;