From fa91aeb065498105bb03f261f33b520c2a093d7a Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 29 Nov 2023 15:04:21 +0300 Subject: [PATCH] Add ContactsManager::fail_load_channel_recommendations_queries. --- td/telegram/ContactsManager.cpp | 29 ++++++++++++++++------------- td/telegram/ContactsManager.h | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 9c4285a48..2a78d2bf0 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9794,14 +9794,18 @@ void ContactsManager::load_channel_recommendations(ChannelId channel_id, bool us } } +void ContactsManager::fail_load_channel_recommendations_queries(ChannelId channel_id, Status &&error) { + auto it = get_channel_recommendations_queries_.find(channel_id); + CHECK(it != get_channel_recommendations_queries_.end()); + auto promises = std::move(it->second); + CHECK(!promises.empty()); + get_channel_recommendations_queries_.erase(it); + fail_promises(promises, std::move(error)); +} + void ContactsManager::on_load_channel_recommendations_from_database(ChannelId channel_id, string value) { if (G()->close_flag()) { - auto it = get_channel_recommendations_queries_.find(channel_id); - CHECK(it != get_channel_recommendations_queries_.end()); - auto promises = std::move(it->second); - CHECK(!promises.empty()); - get_channel_recommendations_queries_.erase(it); - return fail_promises(promises, G()->close_status()); + return fail_load_channel_recommendations_queries(channel_id, G()->close_status()); } if (value.empty()) { @@ -9847,14 +9851,8 @@ void ContactsManager::on_get_channel_recommendations( ChannelId channel_id, Result>>> &&r_chats) { G()->ignore_result_if_closing(r_chats); - auto it = get_channel_recommendations_queries_.find(channel_id); - CHECK(it != get_channel_recommendations_queries_.end()); - auto promises = std::move(it->second); - CHECK(!promises.empty()); - get_channel_recommendations_queries_.erase(it); - if (r_chats.is_error()) { - return fail_promises(promises, r_chats.move_as_error()); + return fail_load_channel_recommendations_queries(channel_id, r_chats.move_as_error()); } auto chats = r_chats.move_as_ok(); @@ -9885,6 +9883,11 @@ void ContactsManager::on_get_channel_recommendations( log_event_store(recommended_dialogs).as_slice().str(), Promise()); } + auto it = get_channel_recommendations_queries_.find(channel_id); + CHECK(it != get_channel_recommendations_queries_.end()); + auto promises = std::move(it->second); + CHECK(!promises.empty()); + get_channel_recommendations_queries_.erase(it); for (auto &promise : promises) { if (promise) { promise.set_value( diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 339e121fa..14155d473 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1748,6 +1748,8 @@ class ContactsManager final : public Actor { void load_channel_recommendations(ChannelId channel_id, bool use_database, Promise> &&promise); + void fail_load_channel_recommendations_queries(ChannelId channel_id, Status &&error); + void on_load_channel_recommendations_from_database(ChannelId channel_id, string value); void reload_channel_recommendations(ChannelId channel_id);