Use Promise instead of RequestActor in getBackgrounds.
This commit is contained in:
parent
d2f9c264ca
commit
7dffe5aabe
@ -411,8 +411,9 @@ void BackgroundManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
|
||||
void BackgroundManager::get_backgrounds(Promise<Unit> &&promise) {
|
||||
pending_get_backgrounds_queries_.push_back(std::move(promise));
|
||||
void BackgroundManager::get_backgrounds(bool for_dark_theme,
|
||||
Promise<td_api::object_ptr<td_api::backgrounds>> &&promise) {
|
||||
pending_get_backgrounds_queries_.emplace_back(for_dark_theme, std::move(promise));
|
||||
if (pending_get_backgrounds_queries_.size() == 1) {
|
||||
auto request_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::account_WallPapers>> result) {
|
||||
@ -1142,7 +1143,7 @@ void BackgroundManager::on_get_backgrounds(Result<telegram_api::object_ptr<teleg
|
||||
|
||||
auto error = result.move_as_error();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
promise.second.set_error(error.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1151,7 +1152,7 @@ void BackgroundManager::on_get_backgrounds(Result<telegram_api::object_ptr<teleg
|
||||
LOG(INFO) << "Receive " << to_string(wallpapers_ptr);
|
||||
if (wallpapers_ptr->get_id() == telegram_api::account_wallPapersNotModified::ID) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
promise.second.set_value(get_backgrounds_object(promise.first));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1166,7 +1167,7 @@ void BackgroundManager::on_get_backgrounds(Result<telegram_api::object_ptr<teleg
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
promise.second.set_value(get_backgrounds_object(promise.first));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class BackgroundManager final : public Actor {
|
||||
public:
|
||||
BackgroundManager(Td *td, ActorShared<> parent);
|
||||
|
||||
void get_backgrounds(Promise<Unit> &&promise);
|
||||
void get_backgrounds(bool for_dark_theme, Promise<td_api::object_ptr<td_api::backgrounds>> &&promise);
|
||||
|
||||
Result<string> get_background_url(const string &name,
|
||||
td_api::object_ptr<td_api::BackgroundType> background_type) const;
|
||||
@ -53,8 +53,6 @@ class BackgroundManager final : public Actor {
|
||||
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id, bool for_dark_theme,
|
||||
const BackgroundType *type) const;
|
||||
|
||||
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object(bool for_dark_theme) const;
|
||||
|
||||
std::pair<BackgroundId, BackgroundType> on_get_background(
|
||||
BackgroundId expected_background_id, const string &expected_background_name,
|
||||
telegram_api::object_ptr<telegram_api::WallPaper> wallpaper_ptr, bool replace_type);
|
||||
@ -110,6 +108,8 @@ class BackgroundManager final : public Actor {
|
||||
|
||||
td_api::object_ptr<td_api::updateSelectedBackground> get_update_selected_background_object(bool for_dark_theme) const;
|
||||
|
||||
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object(bool for_dark_theme) const;
|
||||
|
||||
void send_update_selected_background(bool for_dark_theme) const;
|
||||
|
||||
void set_max_local_background_id(BackgroundId background_id);
|
||||
@ -170,7 +170,7 @@ class BackgroundManager final : public Actor {
|
||||
|
||||
vector<std::pair<BackgroundId, BackgroundType>> installed_backgrounds_;
|
||||
|
||||
vector<Promise<Unit>> pending_get_backgrounds_queries_;
|
||||
vector<std::pair<bool, Promise<td_api::object_ptr<td_api::backgrounds>>>> pending_get_backgrounds_queries_;
|
||||
|
||||
std::shared_ptr<UploadBackgroundFileCallback> upload_background_file_callback_;
|
||||
|
||||
|
@ -2846,23 +2846,6 @@ class GetSupportUserRequest final : public RequestActor<> {
|
||||
}
|
||||
};
|
||||
|
||||
class GetBackgroundsRequest final : public RequestOnceActor {
|
||||
bool for_dark_theme_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) final {
|
||||
td->background_manager_->get_backgrounds(std::move(promise));
|
||||
}
|
||||
|
||||
void do_send_result() final {
|
||||
send_result(td->background_manager_->get_backgrounds_object(for_dark_theme_));
|
||||
}
|
||||
|
||||
public:
|
||||
GetBackgroundsRequest(ActorShared<Td> td, uint64 request_id, bool for_dark_theme)
|
||||
: RequestOnceActor(std::move(td), request_id), for_dark_theme_(for_dark_theme) {
|
||||
}
|
||||
};
|
||||
|
||||
class SearchBackgroundRequest final : public RequestActor<> {
|
||||
string name_;
|
||||
|
||||
@ -8041,7 +8024,8 @@ void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getBackgrounds &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST(GetBackgroundsRequest, request.for_dark_theme_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
background_manager_->get_backgrounds(request.for_dark_theme_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getBackgroundUrl &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user