Add ContactsManager::fail_load_channel_recommendations_queries.

This commit is contained in:
levlam 2023-11-29 15:04:21 +03:00
parent f792e9d45e
commit fa91aeb065
2 changed files with 18 additions and 13 deletions

View File

@ -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) { void ContactsManager::on_load_channel_recommendations_from_database(ChannelId channel_id, string value) {
if (G()->close_flag()) { if (G()->close_flag()) {
auto it = get_channel_recommendations_queries_.find(channel_id); return fail_load_channel_recommendations_queries(channel_id, G()->close_status());
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());
} }
if (value.empty()) { if (value.empty()) {
@ -9847,14 +9851,8 @@ void ContactsManager::on_get_channel_recommendations(
ChannelId channel_id, Result<std::pair<int32, vector<tl_object_ptr<telegram_api::Chat>>>> &&r_chats) { ChannelId channel_id, Result<std::pair<int32, vector<tl_object_ptr<telegram_api::Chat>>>> &&r_chats) {
G()->ignore_result_if_closing(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()) { 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(); 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<Unit>()); log_event_store(recommended_dialogs).as_slice().str(), Promise<Unit>());
} }
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) { for (auto &promise : promises) {
if (promise) { if (promise) {
promise.set_value( promise.set_value(

View File

@ -1748,6 +1748,8 @@ class ContactsManager final : public Actor {
void load_channel_recommendations(ChannelId channel_id, bool use_database, void load_channel_recommendations(ChannelId channel_id, bool use_database,
Promise<td_api::object_ptr<td_api::chats>> &&promise); Promise<td_api::object_ptr<td_api::chats>> &&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 on_load_channel_recommendations_from_database(ChannelId channel_id, string value);
void reload_channel_recommendations(ChannelId channel_id); void reload_channel_recommendations(ChannelId channel_id);