Add loadChats method.
This commit is contained in:
parent
a71850e15e
commit
c35321b98e
@ -4022,6 +4022,11 @@ getFile file_id:int32 = File;
|
||||
//@remote_file_id Remote identifier of the file to get @file_type File type, if known
|
||||
getRemoteFile remote_file_id:string file_type:FileType = File;
|
||||
|
||||
//@description Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats has been loaded
|
||||
//@chat_list The chat list in which to load chats
|
||||
//@limit The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
|
||||
loadChats chat_list:ChatList limit:int32 = Ok;
|
||||
|
||||
//@description Returns an ordered list of chats in a chat list. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. (For example, to get a list of chats from the beginning, the offset_order should be equal to a biggest signed 64-bit number 9223372036854775807 == 2^63 - 1).
|
||||
//-For optimal performance, the number of returned chats is chosen by TDLib
|
||||
//@chat_list The chat list in which to return chats
|
||||
|
@ -15549,6 +15549,16 @@ void MessagesManager::on_load_recommended_dialog_filters(
|
||||
promise.set_value(td_api::make_object<td_api::recommendedChatFilters>(std::move(chat_filters)));
|
||||
}
|
||||
|
||||
Result<DialogDate> MessagesManager::get_dialog_list_last_date(DialogListId dialog_list_id) {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
|
||||
auto *list_ptr = get_dialog_list(dialog_list_id);
|
||||
if (list_ptr == nullptr) {
|
||||
return Status::Error(3, "Chat list not found");
|
||||
}
|
||||
return list_ptr->list_last_dialog_date_;
|
||||
}
|
||||
|
||||
std::pair<int32, vector<DialogId>> MessagesManager::get_dialogs(DialogListId dialog_list_id, DialogDate offset,
|
||||
int32 limit, bool force, Promise<Unit> &&promise) {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
|
@ -522,6 +522,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void get_recommended_dialog_filters(Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
|
||||
|
||||
Result<DialogDate> get_dialog_list_last_date(DialogListId dialog_list_id);
|
||||
|
||||
std::pair<int32, vector<DialogId>> get_dialogs(DialogListId dialog_list_id, DialogDate offset, int32 limit,
|
||||
bool force, Promise<Unit> &&promise);
|
||||
|
||||
|
@ -785,6 +785,23 @@ class GetChatFilterRequest final : public RequestActor<> {
|
||||
}
|
||||
};
|
||||
|
||||
class LoadChatsRequest final : public RequestActor<> {
|
||||
DialogListId dialog_list_id_;
|
||||
DialogDate offset_;
|
||||
int32 limit_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) final {
|
||||
td->messages_manager_->get_dialogs(dialog_list_id_, offset_, limit_, get_tries() < 2, std::move(promise));
|
||||
}
|
||||
|
||||
public:
|
||||
LoadChatsRequest(ActorShared<Td> td, uint64 request_id, DialogListId dialog_list_id, DialogDate offset, int32 limit)
|
||||
: RequestActor(std::move(td), request_id), dialog_list_id_(dialog_list_id), offset_(offset), limit_(limit) {
|
||||
// 1 for database + 1 for server request + 1 for server request at the end + 1 for return + 1 just in case
|
||||
set_tries(5);
|
||||
}
|
||||
};
|
||||
|
||||
class GetChatsRequest final : public RequestActor<> {
|
||||
DialogListId dialog_list_id_;
|
||||
DialogDate offset_;
|
||||
@ -5321,6 +5338,22 @@ void Td::on_request(uint64 id, const td_api::removeTopChat &request) {
|
||||
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::ok>());
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::loadChats &request) {
|
||||
CHECK_IS_USER();
|
||||
|
||||
DialogListId dialog_list_id(request.chat_list_);
|
||||
auto r_offset = messages_manager_->get_dialog_list_last_date(dialog_list_id);
|
||||
if (r_offset.is_error()) {
|
||||
return send_error_raw(id, 400, r_offset.error().message());
|
||||
}
|
||||
auto offset = r_offset.move_as_ok();
|
||||
if (offset == MAX_DIALOG_DATE) {
|
||||
return send_closure(actor_id(this), &Td::send_result, id, nullptr);
|
||||
}
|
||||
|
||||
CREATE_REQUEST(LoadChatsRequest, dialog_list_id, offset, request.limit_);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChats &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST(GetChatsRequest, DialogListId(request.chat_list_), request.offset_order_, request.offset_chat_id_,
|
||||
|
@ -546,6 +546,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::removeTopChat &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::loadChats &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getChats &request);
|
||||
|
||||
void on_request(uint64 id, td_api::searchPublicChat &request);
|
||||
|
@ -944,7 +944,7 @@ class CliClient final : public Actor {
|
||||
td_client_ = create_actor<ClientActor>(name, make_unique<TdCallbackImpl>(this, ++generation_), std::move(options));
|
||||
|
||||
if (get_chat_list_) {
|
||||
send_request(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<int64>::max(), 0, 100));
|
||||
send_request(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<int64>::max(), 0, 10000));
|
||||
}
|
||||
if (disable_network_) {
|
||||
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeNone>()));
|
||||
@ -1978,6 +1978,8 @@ class CliClient final : public Actor {
|
||||
}
|
||||
send_request(td_api::make_object<td_api::getChats>(as_chat_list(op), offset_order, as_chat_id(offset_chat_id),
|
||||
as_limit(limit, 10000)));
|
||||
} else if (op == "lc" || op == "lca" || begins_with(op, "lc-")) {
|
||||
send_request(td_api::make_object<td_api::loadChats>(as_chat_list(op), as_limit(args, 10000)));
|
||||
} else if (op == "gctest") {
|
||||
send_request(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<int64>::max(), 0, 1));
|
||||
send_request(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<int64>::max(), 0, 10));
|
||||
|
Loading…
Reference in New Issue
Block a user