Add Global::ignore_result_if_closing.

This commit is contained in:
levlam 2023-02-16 13:35:27 +03:00
parent 337bdc5f5e
commit 6cf6f32418
8 changed files with 26 additions and 51 deletions

View File

@ -363,9 +363,7 @@ void AutosaveManager::on_get_autosave_settings(
reload_autosave_settings();
}
};
if (G()->close_flag() && r_settings.is_ok()) {
r_settings = Global::request_aborted_error();
}
G()->ignore_result_if_closing(r_settings);
if (r_settings.is_error()) {
return fail_promises(load_settings_queries_, r_settings.move_as_error());
}

View File

@ -9177,9 +9177,7 @@ void ContactsManager::reload_created_public_dialogs(PublicDialogType type,
}
void ContactsManager::finish_get_created_public_dialogs(PublicDialogType type, Result<Unit> &&result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto index = static_cast<int32>(type);
auto promises = std::move(get_created_public_channels_queries_[index]);

View File

@ -433,6 +433,13 @@ class Global final : public ActorContext {
return Status::Error(500, "Request aborted");
}
template <class T>
void ignore_result_if_closing(Result<T> &result) const {
if (close_flag() && result.is_ok()) {
result = request_aborted_error();
}
}
void set_close_flag() {
close_flag_ = true;
}

View File

@ -1438,9 +1438,7 @@ void GroupCallManager::reload_group_call(InputGroupCallId input_group_call_id,
void GroupCallManager::finish_get_group_call(InputGroupCallId input_group_call_id,
Result<tl_object_ptr<telegram_api::phone_groupCall>> &&result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto it = load_group_call_queries_.find(input_group_call_id);
CHECK(it != load_group_call_queries_.end());

View File

@ -23970,9 +23970,7 @@ MessagesManager::FoundMessages MessagesManager::offline_search_messages(DialogId
void MessagesManager::on_message_db_fts_result(Result<MessageDbFtsResult> result, string offset, int32 limit,
int64 random_id, Promise<Unit> &&promise) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
if (result.is_error()) {
found_fts_messages_.erase(random_id);
return promise.set_error(result.move_as_error());
@ -24002,9 +24000,7 @@ void MessagesManager::on_message_db_fts_result(Result<MessageDbFtsResult> result
void MessagesManager::on_message_db_calls_result(Result<MessageDbCallsResult> result, int64 random_id,
MessageId first_db_message_id, MessageSearchFilter filter,
Promise<Unit> &&promise) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
if (result.is_error()) {
found_call_messages_.erase(random_id);
return promise.set_error(result.move_as_error());
@ -30191,9 +30187,7 @@ void MessagesManager::upload_imported_message_attachment(DialogId dialog_id, int
}
void MessagesManager::on_imported_message_attachments_uploaded(int64 random_id, Result<Unit> &&result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto it = pending_message_imports_.find(random_id);
CHECK(it != pending_message_imports_.end());
@ -30920,9 +30914,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog
int32 limit,
Result<vector<MessageDbDialogMessage>> result,
Promise<vector<Notification>> promise) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}

View File

@ -244,9 +244,7 @@ void SponsoredMessageManager::get_dialog_sponsored_messages(
void SponsoredMessageManager::on_get_dialog_sponsored_messages(
DialogId dialog_id, Result<telegram_api::object_ptr<telegram_api::messages_SponsoredMessages>> &&result) {
if (result.is_ok() && G()->close_flag()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto &messages = dialog_sponsored_messages_[dialog_id];
CHECK(messages != nullptr);

View File

@ -4965,9 +4965,7 @@ void StickersManager::on_find_custom_emojis_success(const string &emoji,
void StickersManager::on_load_custom_emojis(string emoji, int64 hash, vector<CustomEmojiId> custom_emoji_ids,
Result<td_api::object_ptr<td_api::stickers>> &&result) {
if (result.is_ok() && G()->close_flag()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
if (result.is_error()) {
return on_find_custom_emojis_fail(emoji, result.move_as_error());
}
@ -5672,9 +5670,7 @@ void StickersManager::do_reload_sticker_set(StickerSetId sticker_set_id,
}
void StickersManager::on_reload_sticker_set(StickerSetId sticker_set_id, Result<Unit> &&result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
LOG(INFO) << "Reloaded " << sticker_set_id;
auto it = sticker_set_reload_queries_.find(sticker_set_id);
CHECK(it != sticker_set_reload_queries_.end());
@ -6602,9 +6598,8 @@ void StickersManager::reload_default_dialog_photo_custom_emoji_ids(bool for_user
void StickersManager::on_get_default_dialog_photo_custom_emoji_ids(
bool for_user, Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list) {
if (G()->close_flag()) {
r_emoji_list = Global::request_aborted_error();
}
G()->ignore_result_if_closing(r_emoji_list);
CHECK(are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user]);
are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user] = false;
@ -8218,9 +8213,7 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, tl_object_ptr<tel
}
void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto it = pending_new_sticker_sets_.find(random_id);
CHECK(it != pending_new_sticker_sets_.end());
@ -8329,9 +8322,7 @@ void StickersManager::do_add_sticker_to_set(UserId user_id, string short_name,
}
void StickersManager::on_added_sticker_uploaded(int64 random_id, Result<Unit> result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto it = pending_add_sticker_to_sets_.find(random_id);
CHECK(it != pending_add_sticker_to_sets_.end());
@ -8430,9 +8421,7 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_
}
void StickersManager::on_sticker_set_thumbnail_uploaded(int64 random_id, Result<Unit> result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
auto it = pending_set_sticker_set_thumbnails_.find(random_id);
CHECK(it != pending_set_sticker_set_thumbnails_.end());
@ -9747,9 +9736,7 @@ void StickersManager::load_emoji_keywords_difference(const string &language_code
void StickersManager::on_get_emoji_keywords_difference(
const string &language_code, int32 from_version,
Result<telegram_api::object_ptr<telegram_api::emojiKeywordsDifference>> &&result) {
if (G()->close_flag() && result.is_ok()) {
result = Global::request_aborted_error();
}
G()->ignore_result_if_closing(result);
if (result.is_error()) {
if (!G()->is_expected_error(result.error())) {
LOG(ERROR) << "Receive " << result.error() << " from GetEmojiKeywordsDifferenceQuery";
@ -10026,9 +10013,8 @@ void StickersManager::reload_emoji_groups(EmojiGroupType group_type, string used
void StickersManager::on_get_emoji_groups(
EmojiGroupType group_type, string used_language_codes,
Result<telegram_api::object_ptr<telegram_api::messages_EmojiGroups>> r_emoji_groups) {
if (G()->close_flag() && r_emoji_groups.is_ok()) {
r_emoji_groups = Global::request_aborted_error();
}
G()->ignore_result_if_closing(r_emoji_groups);
auto type = static_cast<int32>(group_type);
if (r_emoji_groups.is_error()) {
if (!G()->is_expected_error(r_emoji_groups.error())) {

View File

@ -940,9 +940,7 @@ void WebPagesManager::on_load_web_page_instant_view_from_database(WebPageId web_
void WebPagesManager::update_web_page_instant_view_load_requests(WebPageId web_page_id, bool force_update,
Result<WebPageId> r_web_page_id) {
if (G()->close_flag() && r_web_page_id.is_ok()) {
r_web_page_id = Global::request_aborted_error();
}
G()->ignore_result_if_closing(r_web_page_id);
LOG(INFO) << "Update load requests for " << web_page_id;
auto it = load_web_page_instant_view_queries_.find(web_page_id);
if (it == load_web_page_instant_view_queries_.end()) {