Add set_promises/fail_promises helper functions.
This commit is contained in:
parent
4612910a14
commit
163e739302
@ -588,11 +588,7 @@ void AnimationsManager::on_load_saved_animations_finished(vector<FileId> &&saved
|
||||
saved_animation_ids_ = std::move(saved_animation_ids);
|
||||
are_saved_animations_loaded_ = true;
|
||||
send_update_saved_animations(from_database);
|
||||
auto promises = std::move(load_saved_animations_queries_);
|
||||
load_saved_animations_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_saved_animations_queries_);
|
||||
}
|
||||
|
||||
void AnimationsManager::on_get_saved_animations(
|
||||
@ -637,11 +633,7 @@ void AnimationsManager::on_get_saved_animations(
|
||||
}
|
||||
|
||||
if (is_repair) {
|
||||
auto promises = std::move(repair_saved_animations_queries_);
|
||||
repair_saved_animations_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(repair_saved_animations_queries_);
|
||||
} else {
|
||||
on_load_saved_animations_finished(std::move(saved_animation_ids));
|
||||
|
||||
@ -657,12 +649,7 @@ void AnimationsManager::on_get_saved_animations_failed(bool is_repair, Status er
|
||||
are_saved_animations_being_loaded_ = false;
|
||||
next_saved_animations_load_time_ = Time::now_cached() + Random::fast(5, 10);
|
||||
}
|
||||
auto &queries = is_repair ? repair_saved_animations_queries_ : load_saved_animations_queries_;
|
||||
auto promises = std::move(queries);
|
||||
queries.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(is_repair ? repair_saved_animations_queries_ : load_saved_animations_queries_, std::move(error));
|
||||
}
|
||||
|
||||
int64 AnimationsManager::get_saved_animations_hash(const char *source) const {
|
||||
|
@ -565,9 +565,7 @@ void BackgroundManager::on_load_background_from_database(string name, string val
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateSelectedBackground> BackgroundManager::get_update_selected_background_object(
|
||||
|
@ -1147,47 +1147,32 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
|
||||
auto result_ptr = fetch_result<telegram_api::help_dismissSuggestion>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(promises, result_ptr.move_as_error());
|
||||
return;
|
||||
}
|
||||
remove_suggested_action(suggested_actions_, suggested_action);
|
||||
reget_app_config(Auto());
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
return;
|
||||
}
|
||||
if (token == 6 || token == 7) {
|
||||
is_set_archive_and_mute_request_sent_ = false;
|
||||
bool archive_and_mute = (token == 7);
|
||||
auto promises = std::move(set_archive_and_mute_queries_[archive_and_mute]);
|
||||
set_archive_and_mute_queries_[archive_and_mute].clear();
|
||||
CHECK(!promises.empty());
|
||||
auto result_ptr = fetch_result<telegram_api::account_setGlobalPrivacySettings>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(set_archive_and_mute_queries_[archive_and_mute], result_ptr.move_as_error());
|
||||
} else {
|
||||
if (last_set_archive_and_mute_ == archive_and_mute) {
|
||||
do_set_archive_and_mute(archive_and_mute);
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(set_archive_and_mute_queries_[archive_and_mute]);
|
||||
}
|
||||
|
||||
if (!set_archive_and_mute_queries_[!archive_and_mute].empty()) {
|
||||
if (archive_and_mute == last_set_archive_and_mute_) {
|
||||
promises = std::move(set_archive_and_mute_queries_[!archive_and_mute]);
|
||||
set_archive_and_mute_queries_[!archive_and_mute].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(set_archive_and_mute_queries_[!archive_and_mute]);
|
||||
} else {
|
||||
set_archive_and_mute(!archive_and_mute, Auto());
|
||||
}
|
||||
@ -1195,14 +1180,9 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
return;
|
||||
}
|
||||
if (token == 5) {
|
||||
auto promises = std::move(get_global_privacy_settings_queries_);
|
||||
get_global_privacy_settings_queries_.clear();
|
||||
CHECK(!promises.empty());
|
||||
auto result_ptr = fetch_result<telegram_api::account_getGlobalPrivacySettings>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(get_global_privacy_settings_queries_, result_ptr.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1213,40 +1193,27 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
LOG(ERROR) << "Receive wrong response: " << to_string(result);
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(get_global_privacy_settings_queries_);
|
||||
return;
|
||||
}
|
||||
if (token == 3 || token == 4) {
|
||||
is_set_content_settings_request_sent_ = false;
|
||||
bool ignore_sensitive_content_restrictions = (token == 4);
|
||||
auto promises = std::move(set_content_settings_queries_[ignore_sensitive_content_restrictions]);
|
||||
set_content_settings_queries_[ignore_sensitive_content_restrictions].clear();
|
||||
CHECK(!promises.empty());
|
||||
auto result_ptr = fetch_result<telegram_api::account_setContentSettings>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions], result_ptr.move_as_error());
|
||||
} else {
|
||||
if (G()->shared_config().get_option_boolean("can_ignore_sensitive_content_restrictions") &&
|
||||
last_set_content_settings_ == ignore_sensitive_content_restrictions) {
|
||||
do_set_ignore_sensitive_content_restrictions(ignore_sensitive_content_restrictions);
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(set_content_settings_queries_[ignore_sensitive_content_restrictions]);
|
||||
}
|
||||
|
||||
if (!set_content_settings_queries_[!ignore_sensitive_content_restrictions].empty()) {
|
||||
if (ignore_sensitive_content_restrictions == last_set_content_settings_) {
|
||||
promises = std::move(set_content_settings_queries_[!ignore_sensitive_content_restrictions]);
|
||||
set_content_settings_queries_[!ignore_sensitive_content_restrictions].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(set_content_settings_queries_[!ignore_sensitive_content_restrictions]);
|
||||
} else {
|
||||
set_content_settings(!ignore_sensitive_content_restrictions, Auto());
|
||||
}
|
||||
@ -1254,14 +1221,9 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
return;
|
||||
}
|
||||
if (token == 2) {
|
||||
auto promises = std::move(get_content_settings_queries_);
|
||||
get_content_settings_queries_.clear();
|
||||
CHECK(!promises.empty());
|
||||
auto result_ptr = fetch_result<telegram_api::account_getContentSettings>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(get_content_settings_queries_, result_ptr.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1269,9 +1231,7 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
do_set_ignore_sensitive_content_restrictions(result->sensitive_enabled_);
|
||||
G()->shared_config().set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(get_content_settings_queries_);
|
||||
return;
|
||||
}
|
||||
if (token == 1) {
|
||||
@ -1282,12 +1242,8 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
CHECK(!promises.empty() || !unit_promises.empty());
|
||||
auto result_ptr = fetch_result<telegram_api::help_getAppConfig>(std::move(res));
|
||||
if (result_ptr.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
for (auto &promise : unit_promises) {
|
||||
promise.set_error(result_ptr.error().clone());
|
||||
}
|
||||
fail_promises(promises, result_ptr.error().clone());
|
||||
fail_promises(unit_promises, result_ptr.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1296,9 +1252,7 @@ void ConfigManager::on_result(NetQueryPtr res) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(convert_json_value_object(result));
|
||||
}
|
||||
for (auto &promise : unit_promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(unit_promises);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5507,11 +5507,7 @@ void ContactsManager::on_load_imported_contacts_finished() {
|
||||
all_imported_contacts_.clear();
|
||||
}
|
||||
are_imported_contacts_loaded_ = true;
|
||||
auto promises = std::move(load_imported_contacts_queries_);
|
||||
load_imported_contacts_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_imported_contacts_queries_);
|
||||
}
|
||||
|
||||
std::pair<vector<UserId>, vector<int32>> ContactsManager::change_imported_contacts(vector<Contact> &contacts,
|
||||
@ -7877,9 +7873,7 @@ void ContactsManager::finish_get_created_public_dialogs(PublicDialogType type, R
|
||||
result = G()->close_status();
|
||||
}
|
||||
if (result.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -8084,17 +8078,13 @@ void ContactsManager::on_dismiss_suggested_action(SuggestedAction action, Result
|
||||
dismiss_suggested_action_queries_.erase(it);
|
||||
|
||||
if (result.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
remove_dialog_suggested_action(action);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void ContactsManager::on_import_contacts_finished(int64 random_id, vector<UserId> imported_contact_user_ids,
|
||||
@ -8269,11 +8259,7 @@ void ContactsManager::save_contacts_to_database() {
|
||||
void ContactsManager::on_get_contacts_failed(Status error) {
|
||||
CHECK(error.is_error());
|
||||
next_contacts_sync_date_ = G()->unix_time() + Random::fast(5, 10);
|
||||
auto promises = std::move(load_contacts_queries_);
|
||||
load_contacts_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(load_contacts_queries_, std::move(error));
|
||||
}
|
||||
|
||||
void ContactsManager::on_load_contacts_from_database(string value) {
|
||||
@ -8309,11 +8295,7 @@ void ContactsManager::on_load_contacts_from_database(string value) {
|
||||
void ContactsManager::on_get_contacts_finished(size_t expected_contact_count) {
|
||||
LOG(INFO) << "Finished to get " << contacts_hints_.size() << " contacts out of expected " << expected_contact_count;
|
||||
are_contacts_loaded_ = true;
|
||||
auto promises = std::move(load_contacts_queries_);
|
||||
load_contacts_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_contacts_queries_);
|
||||
if (expected_contact_count != contacts_hints_.size()) {
|
||||
save_contacts_to_database();
|
||||
}
|
||||
@ -8813,9 +8795,7 @@ void ContactsManager::on_load_user_from_database(UserId user_id, string value, b
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_user_force(UserId user_id) {
|
||||
@ -9118,9 +9098,7 @@ void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value, b
|
||||
LOG(ERROR) << "Can't find " << c->migrated_to_channel_id << " from " << chat_id;
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_chat_force(ChatId chat_id) {
|
||||
@ -9376,9 +9354,7 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_channel_force(ChannelId channel_id) {
|
||||
@ -9616,9 +9592,7 @@ void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat
|
||||
LOG(ERROR) << "Can't find " << c->user_id << " from " << secret_chat_id;
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_secret_chat_force(SecretChatId secret_chat_id) {
|
||||
|
@ -362,15 +362,11 @@ void CountryInfoManager::on_get_country_list(const string &language_code,
|
||||
it->second->next_reload_time = max(Time::now() + Random::fast(60, 120), it->second->next_reload_time);
|
||||
|
||||
// if we have data for the language, then we don't need to fail promises
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(r_country_list.error().clone());
|
||||
}
|
||||
fail_promises(promises, r_country_list.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,9 +375,7 @@ void CountryInfoManager::on_get_country_list(const string &language_code,
|
||||
on_get_country_list_impl(language_code, r_country_list.move_as_ok());
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void CountryInfoManager::on_get_country_list_impl(const string &language_code,
|
||||
|
@ -1459,9 +1459,7 @@ void GroupCallManager::finish_get_group_call(InputGroupCallId input_group_call_i
|
||||
}
|
||||
|
||||
if (result.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2936,16 +2934,10 @@ void GroupCallManager::process_group_call_after_join_requests(InputGroupCallId i
|
||||
return;
|
||||
}
|
||||
|
||||
auto promises = std::move(group_call->after_join);
|
||||
reset_to_empty(group_call->after_join);
|
||||
if (!group_call->is_active || !group_call->is_joined) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
|
||||
}
|
||||
fail_promises(group_call->after_join, Status::Error(400, "GROUPCALL_JOIN_MISSING"));
|
||||
} else {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(group_call->after_join);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4329,10 +4321,7 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
|
||||
// never update ended calls
|
||||
} else if (!call.is_active) {
|
||||
// always update to an ended call, droping also is_joined, is_speaking and other local flags
|
||||
auto promises = std::move(group_call->after_join);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Status::Error(400, "Group call ended"));
|
||||
}
|
||||
fail_promises(group_call->after_join, Status::Error(400, "Group call ended"));
|
||||
*group_call = std::move(call);
|
||||
need_update = true;
|
||||
} else {
|
||||
|
@ -1227,9 +1227,7 @@ void LanguagePackManager::on_get_all_language_pack_strings(
|
||||
}
|
||||
|
||||
if (r_strings.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(r_strings.error().clone());
|
||||
}
|
||||
fail_promises(promises, r_strings.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1533,11 +1531,7 @@ void LanguagePackManager::on_failed_get_difference(string language_pack, string
|
||||
reset_to_empty(language->get_difference_queries_);
|
||||
}
|
||||
}
|
||||
for (auto &query : get_difference_queries) {
|
||||
if (query) {
|
||||
query.set_error(error.clone());
|
||||
}
|
||||
}
|
||||
fail_promises(get_difference_queries, std::move(error));
|
||||
}
|
||||
|
||||
void LanguagePackManager::add_custom_server_language(string language_code, Promise<Unit> &&promise) {
|
||||
|
@ -9898,9 +9898,7 @@ void MessagesManager::on_get_public_dialogs_search_result(const string &query,
|
||||
found_public_dialogs_[query] = get_peers_dialog_ids(std::move(peers));
|
||||
found_on_server_dialogs_[query] = get_peers_dialog_ids(std::move(my_peers));
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void MessagesManager::on_failed_public_dialogs_search(const string &query, Status &&error) {
|
||||
@ -9913,9 +9911,7 @@ void MessagesManager::on_failed_public_dialogs_search(const string &query, Statu
|
||||
found_public_dialogs_[query]; // negative cache
|
||||
found_on_server_dialogs_[query]; // negative cache
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(promises, std::move(error));
|
||||
}
|
||||
|
||||
void MessagesManager::on_get_message_search_result_calendar(
|
||||
@ -16733,9 +16729,7 @@ void MessagesManager::on_load_folder_dialog_list(FolderId folder_id, Result<Unit
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
}
|
||||
|
||||
void MessagesManager::load_folder_dialog_list_from_database(FolderId folder_id, int32 limit, Promise<Unit> &&promise) {
|
||||
@ -17016,9 +17010,7 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
|
||||
auto promises = std::move(dialog_filter_reload_queries_);
|
||||
dialog_filter_reload_queries_.clear();
|
||||
if (r_filters.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(r_filters.error().clone());
|
||||
}
|
||||
fail_promises(promises, r_filters.move_as_error());
|
||||
LOG(WARNING) << "Receive error " << r_filters.error() << " for GetDialogFiltersQuery";
|
||||
need_dialog_filters_reload_ = false;
|
||||
schedule_dialog_filters_reload(Random::fast(60, 5 * 60));
|
||||
@ -17142,9 +17134,7 @@ void MessagesManager::on_get_dialog_filters(Result<vector<tl_object_ptr<telegram
|
||||
if (need_synchronize_dialog_filters()) {
|
||||
synchronize_dialog_filters();
|
||||
}
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool MessagesManager::need_synchronize_dialog_filters() const {
|
||||
@ -19407,9 +19397,7 @@ void MessagesManager::edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_fil
|
||||
|
||||
if (!load_list_promises.empty()) {
|
||||
LOG(INFO) << "Retry loading of chats in " << dialog_list_id;
|
||||
for (auto &promise : load_list_promises) {
|
||||
promise.set_value(Unit()); // try again
|
||||
}
|
||||
set_promises(load_list_promises); // try again
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -19479,10 +19467,7 @@ void MessagesManager::delete_dialog_filter(DialogFilterId dialog_filter_id, cons
|
||||
}
|
||||
}
|
||||
|
||||
auto promises = std::move(list->load_list_queries_);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Status::Error(400, "Chat list not found"));
|
||||
}
|
||||
fail_promises(list->load_list_queries_, Status::Error(400, "Chat list not found"));
|
||||
|
||||
dialog_lists_.erase(dialog_list_id);
|
||||
dialog_filters_.erase(it);
|
||||
@ -22511,11 +22496,7 @@ void MessagesManager::on_load_active_live_location_full_message_ids_from_databas
|
||||
|
||||
void MessagesManager::on_load_active_live_location_messages_finished() {
|
||||
are_active_live_location_messages_loaded_ = true;
|
||||
auto promises = std::move(load_active_live_location_messages_queries_);
|
||||
load_active_live_location_messages_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_active_live_location_messages_queries_);
|
||||
}
|
||||
|
||||
void MessagesManager::try_add_active_live_location(DialogId dialog_id, const Message *m) {
|
||||
@ -24044,9 +24025,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
|
||||
auto promises = std::move(it->second);
|
||||
load_scheduled_messages_from_database_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Global::request_aborted_error());
|
||||
}
|
||||
fail_promises(promises, Global::request_aborted_error());
|
||||
return;
|
||||
}
|
||||
auto d = get_dialog(dialog_id);
|
||||
@ -24089,9 +24068,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
|
||||
auto promises = std::move(it->second);
|
||||
load_scheduled_messages_from_database_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
Result<vector<string>> MessagesManager::get_message_available_reactions(FullMessageId full_message_id) {
|
||||
@ -32406,12 +32383,10 @@ void MessagesManager::on_get_dialog_query_finished(DialogId dialog_id, Status &&
|
||||
get_dialog_query_log_event_id_.erase(log_event_it);
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
if (status.is_ok()) {
|
||||
promise.set_value(Unit());
|
||||
} else {
|
||||
promise.set_error(status.clone());
|
||||
}
|
||||
if (status.is_ok()) {
|
||||
set_promises(promises);
|
||||
} else {
|
||||
fail_promises(promises, std::move(status));
|
||||
}
|
||||
}
|
||||
|
||||
@ -36995,11 +36970,7 @@ void MessagesManager::update_list_last_dialog_date(DialogList &list) {
|
||||
<< " have is_list_further_loaded == " << is_list_further_loaded << " and " << list.load_list_queries_.size()
|
||||
<< " pending load list queries";
|
||||
if (is_list_further_loaded && !list.load_list_queries_.empty()) {
|
||||
auto promises = std::move(list.load_list_queries_);
|
||||
list.load_list_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(list.load_list_queries_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38243,12 +38214,10 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ
|
||||
|
||||
auto promise_it = run_after_get_channel_difference_.find(dialog_id);
|
||||
if (promise_it != run_after_get_channel_difference_.end()) {
|
||||
vector<Promise<Unit>> promises = std::move(promise_it->second);
|
||||
auto promises = std::move(promise_it->second);
|
||||
run_after_get_channel_difference_.erase(promise_it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
auto it = pending_channel_on_get_dialogs_.find(dialog_id);
|
||||
|
@ -1655,9 +1655,7 @@ void NotificationManager::on_notification_processed(NotificationId notification_
|
||||
auto promises = std::move(promise_it->second);
|
||||
push_notification_promises_.erase(promise_it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -638,12 +638,10 @@ void NotificationSettingsManager::on_get_dialog_notification_settings_query_fini
|
||||
auto promises = std::move(it->second);
|
||||
get_dialog_notification_settings_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
if (status.is_ok()) {
|
||||
promise.set_value(Unit());
|
||||
} else {
|
||||
promise.set_error(status.clone());
|
||||
}
|
||||
if (status.is_ok()) {
|
||||
set_promises(promises);
|
||||
} else {
|
||||
fail_promises(promises, std::move(status));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -885,8 +885,10 @@ void PollManager::on_set_poll_answer_finished(PollId poll_id, Result<Unit> &&res
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_result(result.clone());
|
||||
if (result.is_ok()) {
|
||||
set_promises(promises);
|
||||
} else {
|
||||
fail_promises(promises, result.move_as_error());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1020,9 +1022,7 @@ void PollManager::on_get_poll_voters(PollId poll_id, int32 option_id, string off
|
||||
return;
|
||||
}
|
||||
if (result.is_error()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1423,10 +1423,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
||||
auto it = poll_voters_.find(poll_id);
|
||||
if (it != poll_voters_.end()) {
|
||||
for (auto &voters : it->second) {
|
||||
auto promises = std::move(voters.pending_queries);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Status::Error(500, "The poll was changed"));
|
||||
}
|
||||
fail_promises(voters.pending_queries, Status::Error(500, "The poll was changed"));
|
||||
}
|
||||
poll_voters_.erase(it);
|
||||
}
|
||||
|
@ -487,19 +487,19 @@ void PrivacyManager::update_privacy(tl_object_ptr<telegram_api::updatePrivacy> u
|
||||
}
|
||||
|
||||
void PrivacyManager::on_get_result(UserPrivacySetting user_privacy_setting,
|
||||
Result<UserPrivacySettingRules> privacy_rules) {
|
||||
Result<UserPrivacySettingRules> r_privacy_rules) {
|
||||
auto &info = get_info(user_privacy_setting);
|
||||
auto promises = std::move(info.get_promises);
|
||||
reset_to_empty(info.get_promises);
|
||||
for (auto &promise : promises) {
|
||||
if (privacy_rules.is_error()) {
|
||||
promise.set_error(privacy_rules.error().clone());
|
||||
if (r_privacy_rules.is_error()) {
|
||||
promise.set_error(r_privacy_rules.error().clone());
|
||||
} else {
|
||||
promise.set_value(privacy_rules.ok().get_user_privacy_setting_rules_object());
|
||||
promise.set_value(r_privacy_rules.ok().get_user_privacy_setting_rules_object());
|
||||
}
|
||||
}
|
||||
if (privacy_rules.is_ok()) {
|
||||
do_update_privacy(user_privacy_setting, privacy_rules.move_as_ok(), false);
|
||||
if (r_privacy_rules.is_ok()) {
|
||||
do_update_privacy(user_privacy_setting, r_privacy_rules.move_as_ok(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ class PrivacyManager final : public NetQueryCallback {
|
||||
return info_[static_cast<size_t>(key.type())];
|
||||
}
|
||||
|
||||
void on_get_result(UserPrivacySetting user_privacy_setting, Result<UserPrivacySettingRules> privacy_rules);
|
||||
void on_get_result(UserPrivacySetting user_privacy_setting, Result<UserPrivacySettingRules> r_privacy_rules);
|
||||
void do_update_privacy(UserPrivacySetting user_privacy_setting, UserPrivacySettingRules &&privacy_rules,
|
||||
bool from_update);
|
||||
|
||||
|
@ -68,12 +68,10 @@ void QueryCombiner::on_get_query_result(int64 query_id, Result<Unit> &&result) {
|
||||
auto promises = std::move(it->second.promises);
|
||||
queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
if (result.is_ok()) {
|
||||
promise.set_value(Unit());
|
||||
} else {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
if (result.is_ok()) {
|
||||
set_promises(promises);
|
||||
} else {
|
||||
fail_promises(promises, result.move_as_error());
|
||||
}
|
||||
loop();
|
||||
}
|
||||
|
@ -130,9 +130,7 @@ void RecentDialogList::on_load_dialogs(vector<string> &&found_dialogs) {
|
||||
CHECK(!promises.empty());
|
||||
|
||||
if (G()->close_flag()) {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Global::request_aborted_error());
|
||||
}
|
||||
fail_promises(promises, Global::request_aborted_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -162,9 +160,7 @@ void RecentDialogList::on_load_dialogs(vector<string> &&found_dialogs) {
|
||||
save_dialogs();
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void RecentDialogList::add_dialog(DialogId dialog_id) {
|
||||
|
@ -243,9 +243,7 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
|
||||
}
|
||||
if (result.is_error()) {
|
||||
dialog_sponsored_messages_.erase(dialog_id);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,11 +22,7 @@ void StateManager::on_synchronized(bool is_synchronized) {
|
||||
}
|
||||
if (sync_flag_ && !was_sync_) {
|
||||
was_sync_ = true;
|
||||
auto promises = std::move(wait_first_sync_);
|
||||
reset_to_empty(wait_first_sync_);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(wait_first_sync_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1513,11 +1513,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
|
||||
special_sticker_set.is_being_loaded_ = false;
|
||||
|
||||
if (type == SpecialStickerSetType::animated_emoji()) {
|
||||
auto promises = std::move(pending_get_animated_emoji_queries_);
|
||||
reset_to_empty(pending_get_animated_emoji_queries_);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(pending_get_animated_emoji_queries_);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3385,11 +3381,7 @@ void StickersManager::on_get_installed_sticker_sets(bool is_masks,
|
||||
void StickersManager::on_get_installed_sticker_sets_failed(bool is_masks, Status error) {
|
||||
CHECK(error.is_error());
|
||||
next_installed_sticker_sets_load_time_[is_masks] = Time::now_cached() + Random::fast(5, 10);
|
||||
auto promises = std::move(load_installed_sticker_sets_queries_[is_masks]);
|
||||
load_installed_sticker_sets_queries_[is_masks].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(load_installed_sticker_sets_queries_[is_masks], std::move(error));
|
||||
}
|
||||
|
||||
vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool force, Promise<Unit> &&promise) {
|
||||
@ -3672,9 +3664,7 @@ void StickersManager::on_find_stickers_success(const string &emoji,
|
||||
auto promises = std::move(it->second);
|
||||
search_stickers_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void StickersManager::on_find_stickers_fail(const string &emoji, Status &&error) {
|
||||
@ -3689,9 +3679,7 @@ void StickersManager::on_find_stickers_fail(const string &emoji, Status &&error)
|
||||
auto promises = std::move(it->second);
|
||||
search_stickers_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(promises, std::move(error));
|
||||
}
|
||||
|
||||
vector<StickerSetId> StickersManager::get_installed_sticker_sets(bool is_masks, Promise<Unit> &&promise) {
|
||||
@ -3844,9 +3832,7 @@ void StickersManager::on_find_sticker_sets_success(
|
||||
auto promises = std::move(it->second);
|
||||
search_sticker_sets_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
void StickersManager::on_find_sticker_sets_fail(const string &query, Status &&error) {
|
||||
@ -3858,9 +3844,7 @@ void StickersManager::on_find_sticker_sets_fail(const string &query, Status &&er
|
||||
auto promises = std::move(it->second);
|
||||
search_sticker_sets_queries_.erase(it);
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(promises, std::move(error));
|
||||
}
|
||||
|
||||
void StickersManager::change_sticker_set(StickerSetId set_id, bool is_installed, bool is_archived,
|
||||
@ -4064,11 +4048,7 @@ void StickersManager::on_load_installed_sticker_sets_finished(bool is_masks,
|
||||
are_installed_sticker_sets_loaded_[is_masks] = true;
|
||||
need_update_installed_sticker_sets_[is_masks] = true;
|
||||
send_update_installed_sticker_sets(from_database);
|
||||
auto promises = std::move(load_installed_sticker_sets_queries_[is_masks]);
|
||||
load_installed_sticker_sets_queries_[is_masks].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_installed_sticker_sets_queries_[is_masks]);
|
||||
}
|
||||
|
||||
string StickersManager::get_sticker_set_database_key(StickerSetId set_id) {
|
||||
@ -5180,11 +5160,7 @@ void StickersManager::invalidate_old_featured_sticker_sets() {
|
||||
old_featured_sticker_set_ids_.clear();
|
||||
|
||||
old_featured_sticker_set_generation_++;
|
||||
auto promises = std::move(load_old_featured_sticker_sets_queries_);
|
||||
load_old_featured_sticker_sets_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Status::Error(400, "Trending sticker sets were updated"));
|
||||
}
|
||||
fail_promises(load_old_featured_sticker_sets_queries_, Status::Error(400, "Trending sticker sets were updated"));
|
||||
}
|
||||
|
||||
void StickersManager::set_old_featured_sticker_set_count(int32 count) {
|
||||
@ -5307,21 +5283,14 @@ void StickersManager::on_get_featured_sticker_sets(
|
||||
|
||||
void StickersManager::on_get_featured_sticker_sets_failed(int32 offset, int32 limit, uint32 generation, Status error) {
|
||||
CHECK(error.is_error());
|
||||
vector<Promise<Unit>> promises;
|
||||
if (offset >= 0) {
|
||||
if (generation != old_featured_sticker_set_generation_) {
|
||||
return;
|
||||
}
|
||||
promises = std::move(load_old_featured_sticker_sets_queries_);
|
||||
load_old_featured_sticker_sets_queries_.clear();
|
||||
fail_promises(load_old_featured_sticker_sets_queries_, std::move(error));
|
||||
} else {
|
||||
next_featured_sticker_sets_load_time_ = Time::now_cached() + Random::fast(5, 10);
|
||||
promises = std::move(load_featured_sticker_sets_queries_);
|
||||
load_featured_sticker_sets_queries_.clear();
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
fail_promises(load_featured_sticker_sets_queries_, std::move(error));
|
||||
}
|
||||
}
|
||||
|
||||
@ -5400,11 +5369,7 @@ void StickersManager::on_load_featured_sticker_sets_finished(vector<StickerSetId
|
||||
are_featured_sticker_sets_loaded_ = true;
|
||||
need_update_featured_sticker_sets_ = true;
|
||||
send_update_featured_sticker_sets();
|
||||
auto promises = std::move(load_featured_sticker_sets_queries_);
|
||||
load_featured_sticker_sets_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_featured_sticker_sets_queries_);
|
||||
}
|
||||
|
||||
void StickersManager::load_old_featured_sticker_sets(Promise<Unit> &&promise) {
|
||||
@ -5482,11 +5447,7 @@ void StickersManager::on_load_old_featured_sticker_sets_finished(uint32 generati
|
||||
}
|
||||
append(old_featured_sticker_set_ids_, std::move(featured_sticker_set_ids));
|
||||
fix_old_featured_sticker_set_count();
|
||||
auto promises = std::move(load_old_featured_sticker_sets_queries_);
|
||||
load_old_featured_sticker_sets_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_old_featured_sticker_sets_queries_);
|
||||
}
|
||||
|
||||
vector<StickerSetId> StickersManager::get_attached_sticker_sets(FileId file_id, Promise<Unit> &&promise) {
|
||||
@ -6493,11 +6454,7 @@ void StickersManager::on_load_recent_stickers_finished(bool is_attached, vector<
|
||||
recent_sticker_ids_[is_attached] = std::move(recent_sticker_ids);
|
||||
are_recent_stickers_loaded_[is_attached] = true;
|
||||
send_update_recent_stickers(is_attached, from_database);
|
||||
auto promises = std::move(load_recent_stickers_queries_[is_attached]);
|
||||
load_recent_stickers_queries_[is_attached].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_recent_stickers_queries_[is_attached]);
|
||||
}
|
||||
|
||||
void StickersManager::on_get_recent_stickers(bool is_repair, bool is_attached,
|
||||
@ -6530,11 +6487,7 @@ void StickersManager::on_get_recent_stickers(bool is_repair, bool is_attached,
|
||||
}
|
||||
|
||||
if (is_repair) {
|
||||
auto promises = std::move(repair_recent_stickers_queries_[is_attached]);
|
||||
repair_recent_stickers_queries_[is_attached].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(repair_recent_stickers_queries_[is_attached]);
|
||||
} else {
|
||||
on_load_recent_stickers_finished(is_attached, std::move(recent_sticker_ids));
|
||||
|
||||
@ -6547,12 +6500,8 @@ void StickersManager::on_get_recent_stickers_failed(bool is_repair, bool is_atta
|
||||
if (!is_repair) {
|
||||
next_recent_stickers_load_time_[is_attached] = Time::now_cached() + Random::fast(5, 10);
|
||||
}
|
||||
auto &queries = is_repair ? repair_recent_stickers_queries_[is_attached] : load_recent_stickers_queries_[is_attached];
|
||||
auto promises = std::move(queries);
|
||||
queries.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(is_repair ? repair_recent_stickers_queries_[is_attached] : load_recent_stickers_queries_[is_attached],
|
||||
std::move(error));
|
||||
}
|
||||
|
||||
int64 StickersManager::get_recent_stickers_hash(const vector<FileId> &sticker_ids) const {
|
||||
@ -6896,11 +6845,7 @@ void StickersManager::on_load_favorite_stickers_finished(vector<FileId> &&favori
|
||||
favorite_sticker_ids_ = std::move(favorite_sticker_ids);
|
||||
are_favorite_stickers_loaded_ = true;
|
||||
send_update_favorite_stickers(from_database);
|
||||
auto promises = std::move(load_favorite_stickers_queries_);
|
||||
load_favorite_stickers_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(load_favorite_stickers_queries_);
|
||||
}
|
||||
|
||||
void StickersManager::on_get_favorite_stickers(
|
||||
@ -6936,11 +6881,7 @@ void StickersManager::on_get_favorite_stickers(
|
||||
}
|
||||
|
||||
if (is_repair) {
|
||||
auto promises = std::move(repair_favorite_stickers_queries_);
|
||||
repair_favorite_stickers_queries_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(repair_favorite_stickers_queries_);
|
||||
} else {
|
||||
on_load_favorite_stickers_finished(std::move(favorite_sticker_ids));
|
||||
|
||||
@ -6953,12 +6894,7 @@ void StickersManager::on_get_favorite_stickers_failed(bool is_repair, Status err
|
||||
if (!is_repair) {
|
||||
next_favorite_stickers_load_time_ = Time::now_cached() + Random::fast(5, 10);
|
||||
}
|
||||
auto &queries = is_repair ? repair_favorite_stickers_queries_ : load_favorite_stickers_queries_;
|
||||
auto promises = std::move(queries);
|
||||
queries.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
fail_promises(is_repair ? repair_favorite_stickers_queries_ : load_favorite_stickers_queries_, std::move(error));
|
||||
}
|
||||
|
||||
int64 StickersManager::get_favorite_stickers_hash() const {
|
||||
@ -7279,9 +7215,7 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
|
||||
if (!G()->is_expected_error(result.error())) {
|
||||
LOG(ERROR) << "Receive " << result.error() << " from GetEmojiKeywordsLanguageQuery";
|
||||
}
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -7311,9 +7245,7 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
|
||||
it->second = std::move(language_codes);
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
vector<string> StickersManager::get_emoji_language_codes(const vector<string> &input_language_codes, Slice text,
|
||||
@ -7412,9 +7344,7 @@ void StickersManager::on_get_emoji_keywords(
|
||||
if (!G()->is_expected_error(result.error())) {
|
||||
LOG(ERROR) << "Receive " << result.error() << " from GetEmojiKeywordsQuery";
|
||||
}
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(result.error().clone());
|
||||
}
|
||||
fail_promises(promises, result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,10 +135,7 @@ void StorageManager::on_file_stats(Result<FileStats> r_file_stats, uint32 genera
|
||||
return;
|
||||
}
|
||||
if (r_file_stats.is_error()) {
|
||||
auto promises = std::move(pending_storage_stats_);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(r_file_stats.error().clone());
|
||||
}
|
||||
fail_promises(pending_storage_stats_, r_file_stats.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -223,9 +220,7 @@ void StorageManager::on_gc_finished(int32 dialog_limit, Result<FileGcResult> r_f
|
||||
append(promises, std::move(pending_run_gc_[1]));
|
||||
pending_run_gc_[0].clear();
|
||||
pending_run_gc_[1].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(r_file_gc_result.error().clone());
|
||||
}
|
||||
fail_promises(promises, r_file_gc_result.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -288,11 +283,7 @@ void StorageManager::hangup_shared() {
|
||||
}
|
||||
|
||||
void StorageManager::close_stats_worker() {
|
||||
auto promises = std::move(pending_storage_stats_);
|
||||
pending_storage_stats_.clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Global::request_aborted_error());
|
||||
}
|
||||
fail_promises(pending_storage_stats_, Global::request_aborted_error());
|
||||
stats_generation_++;
|
||||
stats_worker_.reset();
|
||||
stats_cancellation_token_source_.cancel();
|
||||
@ -303,9 +294,7 @@ void StorageManager::close_gc_worker() {
|
||||
append(promises, std::move(pending_run_gc_[1]));
|
||||
pending_run_gc_[0].clear();
|
||||
pending_run_gc_[1].clear();
|
||||
for (auto &promise : promises) {
|
||||
promise.set_error(Global::request_aborted_error());
|
||||
}
|
||||
fail_promises(promises, Global::request_aborted_error());
|
||||
gc_worker_.reset();
|
||||
gc_cancellation_token_source_.cancel();
|
||||
}
|
||||
|
@ -1402,10 +1402,7 @@ void UpdatesManager::on_get_difference(tl_object_ptr<telegram_api::updates_Diffe
|
||||
pending_qts_updates_.clear();
|
||||
|
||||
for (auto &pending_update : pending_qts_updates) {
|
||||
auto promises = std::move(pending_update.second.promises);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(pending_update.second.promises);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2412,11 +2409,8 @@ void UpdatesManager::process_pending_qts_updates() {
|
||||
// the update will be applied later
|
||||
break;
|
||||
}
|
||||
auto promise = PromiseCreator::lambda([promises = std::move(update_it->second.promises)](Unit) mutable {
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
});
|
||||
auto promise = PromiseCreator::lambda(
|
||||
[promises = std::move(update_it->second.promises)](Unit) mutable { set_promises(promises); });
|
||||
processed_pending_update = true;
|
||||
if (qts == old_qts + 1) {
|
||||
process_qts_update(std::move(update_it->second.update), qts, std::move(promise));
|
||||
|
@ -1004,9 +1004,7 @@ void WebPagesManager::update_web_page_instant_view_load_requests(WebPageId web_p
|
||||
if (r_web_page_id.is_error()) {
|
||||
LOG(INFO) << "Receive error " << r_web_page_id.error() << " for load " << web_page_id;
|
||||
combine(promises[0], std::move(promises[1]));
|
||||
for (auto &promise : promises[0]) {
|
||||
promise.set_error(r_web_page_id.error().clone());
|
||||
}
|
||||
fail_promises(promises[0], r_web_page_id.move_as_error());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1666,9 +1664,7 @@ void WebPagesManager::on_load_web_page_from_database(WebPageId web_page_id, stri
|
||||
// web page has already been loaded from the server
|
||||
}
|
||||
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
}
|
||||
|
||||
bool WebPagesManager::have_web_page_force(WebPageId web_page_id) {
|
||||
|
@ -723,4 +723,33 @@ class PromiseCreator {
|
||||
}
|
||||
};
|
||||
|
||||
inline void set_promises(vector<Promise<Unit>> &promises) {
|
||||
auto moved_promises = std::move(promises);
|
||||
promises.clear();
|
||||
|
||||
for (auto &promise : moved_promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void fail_promises(vector<Promise<T>> &promises, Status &&error) {
|
||||
CHECK(error.is_error());
|
||||
auto moved_promises = std::move(promises);
|
||||
promises.clear();
|
||||
|
||||
auto size = moved_promises.size();
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
size--;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
auto &promise = moved_promises[i];
|
||||
if (promise) {
|
||||
promise.set_error(error.clone());
|
||||
}
|
||||
}
|
||||
moved_promises[size].set_error(std::move(error));
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -144,10 +144,7 @@ class SqliteKeyValueAsync final : public SqliteKeyValueAsyncInterface {
|
||||
}
|
||||
kv_->commit_transaction().ensure();
|
||||
buffer_.clear();
|
||||
for (auto &promise : buffer_promises_) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
buffer_promises_.clear();
|
||||
set_promises(buffer_promises_);
|
||||
}
|
||||
|
||||
void timeout_expired() final {
|
||||
|
@ -152,10 +152,7 @@ class BinlogActor final : public Actor {
|
||||
if (need_sync) {
|
||||
binlog_->sync();
|
||||
// LOG(ERROR) << "BINLOG SYNC";
|
||||
for (auto &promise : sync_promises_) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
sync_promises_.clear();
|
||||
set_promises(sync_promises_);
|
||||
} else if (need_flush) {
|
||||
try_flush();
|
||||
// LOG(ERROR) << "BINLOG FLUSH";
|
||||
|
@ -433,7 +433,7 @@ class FakeBinlog final
|
||||
has_request_sync = false;
|
||||
auto pos = static_cast<size_t>(Random::fast_uint64() % pending_events_.size());
|
||||
// pos = pending_events_.size() - 1;
|
||||
std::vector<Promise<>> promises;
|
||||
td::vector<Promise<Unit>> promises;
|
||||
for (size_t i = 0; i <= pos; i++) {
|
||||
auto &pending = pending_events_[i];
|
||||
auto event = std::move(pending.event);
|
||||
@ -444,9 +444,7 @@ class FakeBinlog final
|
||||
append(promises, std::move(pending.promises_));
|
||||
}
|
||||
pending_events_.erase(pending_events_.begin(), pending_events_.begin() + pos + 1);
|
||||
for (auto &promise : promises) {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
set_promises(promises);
|
||||
|
||||
for (auto &event : pending_events_) {
|
||||
if (event.sync_flag) {
|
||||
@ -470,7 +468,7 @@ class FakeBinlog final
|
||||
struct PendingEvent {
|
||||
BinlogEvent event;
|
||||
bool sync_flag = false;
|
||||
std::vector<Promise<>> promises_;
|
||||
td::vector<Promise<Unit>> promises_;
|
||||
};
|
||||
|
||||
std::vector<PendingEvent> pending_events_;
|
||||
|
Loading…
Reference in New Issue
Block a user