Fix loading of pinned dialogs.

GitOrigin-RevId: 1ee93b98a10d5f24899d0793e5c9ce1bf3807a85
This commit is contained in:
levlam 2020-06-06 22:41:03 +03:00
parent 2433e68d38
commit b5b1c4c3a6

View File

@ -13845,7 +13845,9 @@ vector<DialogId> MessagesManager::get_dialogs(DialogListId dialog_list_id, Dialo
auto &list = *list_ptr; auto &list = *list_ptr;
LOG(INFO) << "Get chats in " << dialog_list_id << " with offset " << offset << " and limit " << limit LOG(INFO) << "Get chats in " << dialog_list_id << " with offset " << offset << " and limit " << limit
<< ". last_dialog_date = " << list.list_last_dialog_date_; << ". last_dialog_date = " << list.list_last_dialog_date_
<< ", last_pinned_dialog_date_ = " << list.last_pinned_dialog_date_
<< ", are_pinned_dialogs_inited_ = " << list.are_pinned_dialogs_inited_;
if (limit <= 0) { if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit in getChats must be positive")); promise.set_error(Status::Error(3, "Parameter limit in getChats must be positive"));
@ -13869,7 +13871,15 @@ vector<DialogId> MessagesManager::get_dialogs(DialogListId dialog_list_id, Dialo
} }
} }
if (list.are_pinned_dialogs_inited_) { if (!list.are_pinned_dialogs_inited_) {
if (limit == 0 || force) {
promise.set_value(Unit());
} else {
reload_pinned_dialogs(dialog_list_id, std::move(promise));
}
return result;
}
bool need_reload_pinned_dialogs = false; bool need_reload_pinned_dialogs = false;
if (!list.pinned_dialogs_.empty() && offset < list.pinned_dialogs_.back() && limit > 0) { if (!list.pinned_dialogs_.empty() && offset < list.pinned_dialogs_.back() && limit > 0) {
for (auto &pinned_dialog : list.pinned_dialogs_) { for (auto &pinned_dialog : list.pinned_dialogs_) {
@ -13930,18 +13940,16 @@ vector<DialogId> MessagesManager::get_dialogs(DialogListId dialog_list_id, Dialo
result.push_back(folder_iterators[best_pos]->get_dialog_id()); result.push_back(folder_iterators[best_pos]->get_dialog_id());
++folder_iterators[best_pos]; ++folder_iterators[best_pos];
} }
}
if (!result.empty() || force) { if (!result.empty() || force || list.list_last_dialog_date_ == MAX_DIALOG_DATE) {
if (limit > 0) { if (limit > 0 && list.list_last_dialog_date_ != MAX_DIALOG_DATE) {
load_dialog_list(list, limit, Promise<Unit>()); load_dialog_list(list, limit, Promise<Unit>());
} }
promise.set_value(Unit()); promise.set_value(Unit());
return result; } else {
}
load_dialog_list(list, limit, std::move(promise)); load_dialog_list(list, limit, std::move(promise));
}
return result; return result;
} }
@ -13957,6 +13965,8 @@ void MessagesManager::load_dialog_list(DialogList &list, int32 limit, Promise<Un
if (is_request_sent) { if (is_request_sent) {
list.load_list_queries_.push_back(std::move(promise)); list.load_list_queries_.push_back(std::move(promise));
} else { } else {
LOG(ERROR) << "There is nothing to load for " << list.dialog_list_id << " with folders "
<< get_dialog_list_folder_ids(list);
promise.set_value(Unit()); promise.set_value(Unit());
} }
} }