diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 24311f540..ea0458d96 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -681,8 +681,8 @@ message id:int53 sender_user_id:int32 chat_id:int53 sending_state:MessageSending //@description Contains a list of messages @total_count Approximate total count of messages found @messages List of messages; messages may be null messages total_count:int32 messages:vector = Messages; -//@description Contains a list of messages found by a search @messages List of messages @next_from_search_id Value to pass as from_search_id to get more results -foundMessages messages:vector next_from_search_id:int64 = FoundMessages; +//@description Contains a list of messages found by a search @messages List of messages @next_offset The offset for the next request. If empty, there are no more results +foundMessages messages:vector next_offset:string = FoundMessages; //@class NotificationSettingsScope @description Describes the types of chats to which notification settings are applied @@ -3595,10 +3595,10 @@ searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id: //@description Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance the number of returned messages is chosen by the library //@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats @query Query to search for. If empty, searchChatMessages should be used instead -//@from_search_id The identifier from the result of a previous request, use 0 to get results from the last message +//@offset Offset of the first entry to return; use empty string to get results from the last message //@limit The maximum number of messages to be returned; up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached //@filter A filter for the content of messages in the search results -searchSecretMessages chat_id:int53 query:string from_search_id:int64 limit:int32 filter:SearchMessagesFilter = FoundMessages; +searchSecretMessages chat_id:int53 query:string offset:string limit:int32 filter:SearchMessagesFilter = FoundMessages; //@description Searches for call messages. Returns the results in reverse chronological order (i. e., in order of decreasing message_id). For optimal performance the number of returned messages is chosen by the library //@from_message_id Identifier of the message from which to search; use 0 to get results from the last message diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index f7c81db5e..66c70304d 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 247620883..589217118 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18994,8 +18994,8 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo promise.set_value(Unit()); } -std::pair> MessagesManager::offline_search_messages( - DialogId dialog_id, const string &query, int64 from_search_id, int32 limit, +std::pair> MessagesManager::offline_search_messages( + DialogId dialog_id, const string &query, const string &offset, int32 limit, const tl_object_ptr &filter, int64 &random_id, Promise<> &&promise) { if (!G()->parameters().use_message_db) { promise.set_error(Status::Error(400, "Message database is required to search messages in secret chats")); @@ -19032,7 +19032,14 @@ std::pair> MessagesManager::offline_search_messages fts_query.query = query; fts_query.dialog_id = dialog_id; fts_query.index_mask = search_messages_filter_index_mask(get_search_messages_filter(filter)); - fts_query.from_search_id = from_search_id; + if (!offset.empty()) { + auto r_from_search_id = to_integer_safe(offset); + if (r_from_search_id.is_error()) { + promise.set_error(Status::Error(400, "Wrong offset specified")); + return {}; + } + fts_query.from_search_id = r_from_search_id.ok(); + } fts_query.limit = limit; do { @@ -19074,7 +19081,7 @@ void MessagesManager::on_messages_db_fts_result(Result resu } } - it->second.first = fts_result.next_search_id; + it->second.first = fts_result.next_search_id <= 1 ? string() : to_string(fts_result.next_search_id); promise.set_value(Unit()); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 0c627bd99..52a03bf55 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -653,8 +653,8 @@ class MessagesManager : public Actor { const tl_object_ptr &filter, int64 &random_id, bool use_db, Promise &&promise); - std::pair> offline_search_messages( - DialogId dialog_id, const string &query, int64 from_search_id, int32 limit, + std::pair> offline_search_messages( + DialogId dialog_id, const string &query, const string &offset, int32 limit, const tl_object_ptr &filter, int64 &random_id, Promise<> &&promise); std::pair> search_messages(FolderId folder_id, bool ignore_folder_id, @@ -2931,8 +2931,8 @@ class MessagesManager : public Actor { std::unordered_map>> found_dialog_recent_location_messages_; // random_id -> [total_count, [message_id]...] - std::unordered_map>> - found_fts_messages_; // random_id -> [from_search_id, [full_message_id]...] + std::unordered_map>> + found_fts_messages_; // random_id -> [next_offset, [full_message_id]...] std::unordered_map, FullMessageIdHash> public_message_links_[2]; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index f30ff3b5f..730da7a58 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1465,19 +1465,19 @@ class SearchChatMessagesRequest : public RequestActor<> { } }; -class OfflineSearchMessagesRequest : public RequestActor<> { +class SearchSecretMessagesRequest : public RequestActor<> { DialogId dialog_id_; string query_; - int64 from_search_id_; + string offset_; int32 limit_; tl_object_ptr filter_; int64 random_id_; - std::pair> messages_; + std::pair> messages_; void do_run(Promise &&promise) override { - messages_ = td->messages_manager_->offline_search_messages(dialog_id_, query_, from_search_id_, limit_, filter_, - random_id_, std::move(promise)); + messages_ = td->messages_manager_->offline_search_messages(dialog_id_, query_, offset_, limit_, filter_, random_id_, + std::move(promise)); } void do_send_result() override { @@ -1487,16 +1487,16 @@ class OfflineSearchMessagesRequest : public RequestActor<> { result.push_back(td->messages_manager_->get_message_object(full_message_id)); } - send_result(make_tl_object(std::move(result), messages_.first)); + send_result(make_tl_object(std::move(result), std::move(messages_.first))); } public: - OfflineSearchMessagesRequest(ActorShared td, uint64 request_id, int64 dialog_id, string query, - int64 from_search_id, int32 limit, tl_object_ptr filter) + SearchSecretMessagesRequest(ActorShared td, uint64 request_id, int64 dialog_id, string query, string offset, + int32 limit, tl_object_ptr filter) : RequestActor(std::move(td), request_id) , dialog_id_(dialog_id) , query_(std::move(query)) - , from_search_id_(from_search_id) + , offset_(std::move(offset)) , limit_(limit) , filter_(std::move(filter)) , random_id_(0) { @@ -5463,7 +5463,7 @@ void Td::on_request(uint64 id, td_api::searchChatMessages &request) { void Td::on_request(uint64 id, td_api::searchSecretMessages &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.query_); - CREATE_REQUEST(OfflineSearchMessagesRequest, request.chat_id_, std::move(request.query_), request.from_search_id_, + CREATE_REQUEST(SearchSecretMessagesRequest, request.chat_id_, std::move(request.query_), std::move(request.offset_), request.limit_, std::move(request.filter_)); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 19eaf6856..5300c31e0 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2913,19 +2913,18 @@ class CliClient final : public Actor { } } else if (op == "ssm") { string chat_id; - string from_search_id; + string offset; string limit; string filter; string query; std::tie(chat_id, args) = split(args); - std::tie(from_search_id, args) = split(args); + std::tie(offset, args) = split(args); std::tie(limit, args) = split(args); std::tie(filter, query) = split(args); send_request(td_api::make_object( - as_chat_id(chat_id), query, to_integer(from_search_id), to_integer(limit), - get_search_messages_filter(filter))); + as_chat_id(chat_id), query, offset, to_integer(limit), get_search_messages_filter(filter))); } else if (op == "ssd") { schedule_date_ = args; } else if (op == "sm" || op == "sms" || op == "smr" || op == "smf") {