From 85b06f9614b4b7e72e8b19909e3d8ee0f2b492cf Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 29 Nov 2023 15:11:55 +0300 Subject: [PATCH] Add ContactsManager::finish_load_channel_recommendations_queries. --- td/telegram/ContactsManager.cpp | 43 +++++++++++++++------------------ td/telegram/ContactsManager.h | 3 +++ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 2a78d2bf0..9508cdb90 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9803,6 +9803,21 @@ void ContactsManager::fail_load_channel_recommendations_queries(ChannelId channe fail_promises(promises, std::move(error)); } +void ContactsManager::finish_load_channel_recommendations_queries(ChannelId channel_id, int32 total_count, + vector dialog_ids) { + 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(td_->messages_manager_->get_chats_object(total_count, dialog_ids, + "finish_load_channel_recommendations_queries")); + } + } +} + void ContactsManager::on_load_channel_recommendations_from_database(ChannelId channel_id, string value) { if (G()->close_flag()) { return fail_load_channel_recommendations_queries(channel_id, G()->close_status()); @@ -9819,20 +9834,10 @@ void ContactsManager::on_load_channel_recommendations_from_database(ChannelId ch return reload_channel_recommendations(channel_id); } - 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); - auto total_count = recommended_dialogs.total_count_; - auto dialog_ids = recommended_dialogs.dialog_ids_; auto next_reload_time = recommended_dialogs.next_reload_time_; - for (auto &promise : promises) { - if (promise) { - promise.set_value(td_->messages_manager_->get_chats_object(total_count, dialog_ids, - "on_load_channel_recommendations_from_database")); - } - } + finish_load_channel_recommendations_queries(channel_id, recommended_dialogs.total_count_, + recommended_dialogs.dialog_ids_); + if (next_reload_time <= Time::now()) { load_channel_recommendations(channel_id, false, Auto()); } @@ -9883,17 +9888,7 @@ 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( - td_->messages_manager_->get_chats_object(total_count, dialog_ids, "on_get_channel_recommendations")); - } - } + finish_load_channel_recommendations_queries(channel_id, total_count, std::move(dialog_ids)); } void ContactsManager::return_created_public_dialogs(Promise> &&promise, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 14155d473..d26acac4e 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1750,6 +1750,9 @@ class ContactsManager final : public Actor { void fail_load_channel_recommendations_queries(ChannelId channel_id, Status &&error); + void finish_load_channel_recommendations_queries(ChannelId channel_id, int32 total_count, + vector dialog_ids); + void on_load_channel_recommendations_from_database(ChannelId channel_id, string value); void reload_channel_recommendations(ChannelId channel_id);