Combine GetSavedDialogsQuery requests.

This commit is contained in:
levlam 2024-02-07 12:45:13 +03:00
parent 39ea60e889
commit bb5d9d8777
2 changed files with 20 additions and 2 deletions

View File

@ -447,8 +447,23 @@ void SavedMessagesManager::on_get_pinned_saved_dialogs(Result<Unit> &&result) {
}
void SavedMessagesManager::get_saved_dialogs(int32 limit, Promise<Unit> &&promise) {
td_->create_handler<GetSavedDialogsQuery>(std::move(promise))
->send(topic_list_.offset_date_, topic_list_.offset_message_id_, topic_list_.offset_dialog_id_, limit);
topic_list_.load_queries_.push_back(std::move(promise));
if (topic_list_.load_queries_.size() == 1) {
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this)](Result<Unit> &&result) {
send_closure(actor_id, &SavedMessagesManager::on_get_saved_dialogs, std::move(result));
});
td_->create_handler<GetSavedDialogsQuery>(std::move(query_promise))
->send(topic_list_.offset_date_, topic_list_.offset_message_id_, topic_list_.offset_dialog_id_, limit);
}
}
void SavedMessagesManager::on_get_saved_dialogs(Result<Unit> &&result) {
G()->ignore_result_if_closing(result);
if (result.is_error()) {
fail_promises(topic_list_.load_queries_, result.move_as_error());
} else {
set_promises(topic_list_.load_queries_);
}
}
void SavedMessagesManager::on_get_saved_messages_topics(

View File

@ -110,6 +110,7 @@ class SavedMessagesManager final : public Actor {
TopicDate last_topic_date_ = MIN_TOPIC_DATE; // in memory
vector<Promise<Unit>> load_pinned_queries_;
vector<Promise<Unit>> load_queries_;
int32 offset_date_ = std::numeric_limits<int32>::max();
DialogId offset_dialog_id_;
@ -128,6 +129,8 @@ class SavedMessagesManager final : public Actor {
void get_saved_dialogs(int32 limit, Promise<Unit> &&promise);
void on_get_saved_dialogs(Result<Unit> &&result);
void on_get_saved_messages_topic_history(SavedMessagesTopicId saved_messages_topic_id, MessageId from_message_id,
Result<MessagesInfo> &&r_info,
Promise<td_api::object_ptr<td_api::messages>> &&promise);