From ca356088682595ac402b159482c5f09e60afd735 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 22 Oct 2019 15:06:11 +0300 Subject: [PATCH] Add chat_list filter to searchMessages. GitOrigin-RevId: 3dbc4b3509545f3c23f0231c931af0a73bef8796 --- td/generate/scheme/td_api.tl | 3 ++- td/generate/scheme/td_api.tlo | Bin 163324 -> 163360 bytes td/telegram/MessagesManager.cpp | 15 ++++++++++----- td/telegram/MessagesManager.h | 3 ++- td/telegram/Td.cpp | 18 ++++++++++++------ td/telegram/cli.cpp | 13 ++++++++++--- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 6f166dd55..398656802 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3164,12 +3164,13 @@ searchChatMessages chat_id:int53 query:string sender_user_id:int32 from_message_ //@description Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). //-For optimal performance the number of returned messages is chosen by the library +//@chat_list Chat list in which to search messages; pass null to search in all chats regardless of their chat list //@query Query to search for //@offset_date The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message //@offset_chat_id The chat identifier of the last found message, or 0 for the first request //@offset_message_id The message identifier of the last found message, or 0 for the first request //@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 -searchMessages query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 = Messages; +searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 = Messages; //@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 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 797474ab74155dc48c8ab9ce98f3b466f27133fb..3570a5e13dfc20a1e393816b21be6a84d292493c 100644 GIT binary patch delta 41 zcmV+^0M`Hf`w5`@34nwFv;z1?1O;H!eNqu{Q2h#yl03(hK*#H0l diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 063a170ba..34e947295 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1451,8 +1451,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler { explicit SearchMessagesGlobalQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(const string &query, int32 offset_date, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, - int64 random_id) { + void send(FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, + DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, int64 random_id) { query_ = query; offset_date_ = offset_date; offset_dialog_id_ = offset_dialog_id; @@ -1465,8 +1465,12 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler { input_peer = make_tl_object(); } + int32 flags = 0; + if (!ignore_folder_id) { + flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK; + } send_query(G()->net_query_creator().create(create_storer( - telegram_api::messages_searchGlobal(0, false /*ignored*/, query, offset_date_, std::move(input_peer), + telegram_api::messages_searchGlobal(flags, folder_id.get(), query, offset_date_, std::move(input_peer), offset_message_id.get_server_message_id().get(), limit)))); } @@ -15728,7 +15732,8 @@ void MessagesManager::on_messages_db_calls_result(Result promise.set_value(Unit()); } -std::pair> MessagesManager::search_messages(const string &query, int32 offset_date, +std::pair> MessagesManager::search_messages(FolderId folder_id, bool ignore_folder_id, + const string &query, int32 offset_date, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, int64 &random_id, Promise &&promise) { @@ -15777,7 +15782,7 @@ std::pair> MessagesManager::search_messages(const s << offset_dialog_id << ", " << offset_message_id << " and with limit " << limit; td_->create_handler(std::move(promise)) - ->send(query, offset_date, offset_dialog_id, offset_message_id, limit, random_id); + ->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, random_id); return result; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 86365986e..a04c1448c 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -598,7 +598,8 @@ class MessagesManager : public Actor { DialogId dialog_id, const string &query, int64 from_search_id, int32 limit, const tl_object_ptr &filter, int64 &random_id, Promise<> &&promise); - std::pair> search_messages(const string &query, int32 offset_date, + std::pair> search_messages(FolderId folder_id, bool ignore_folder_id, + const string &query, int32 offset_date, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, int64 &random_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 29a346c7f..26c551948 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1530,6 +1530,8 @@ class OfflineSearchMessagesRequest : public RequestActor<> { }; class SearchMessagesRequest : public RequestActor<> { + FolderId folder_id_; + bool ignore_folder_id_; string query_; int32 offset_date_; DialogId offset_dialog_id_; @@ -1540,8 +1542,9 @@ class SearchMessagesRequest : public RequestActor<> { std::pair> messages_; void do_run(Promise &&promise) override { - messages_ = td->messages_manager_->search_messages(query_, offset_date_, offset_dialog_id_, offset_message_id_, - limit_, random_id_, std::move(promise)); + messages_ = + td->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_date_, offset_dialog_id_, + offset_message_id_, limit_, random_id_, std::move(promise)); } void do_send_result() override { @@ -1558,9 +1561,11 @@ class SearchMessagesRequest : public RequestActor<> { } public: - SearchMessagesRequest(ActorShared td, uint64 request_id, string query, int32 offset_date, int64 offset_dialog_id, - int64 offset_message_id, int32 limit) + SearchMessagesRequest(ActorShared td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query, + int32 offset_date, int64 offset_dialog_id, int64 offset_message_id, int32 limit) : RequestActor(std::move(td), request_id) + , folder_id_(folder_id) + , ignore_folder_id_(ignore_folder_id) , query_(std::move(query)) , offset_date_(offset_date) , offset_dialog_id_(offset_dialog_id) @@ -5584,8 +5589,9 @@ void Td::on_request(uint64 id, td_api::searchSecretMessages &request) { void Td::on_request(uint64 id, td_api::searchMessages &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.query_); - CREATE_REQUEST(SearchMessagesRequest, std::move(request.query_), request.offset_date_, request.offset_chat_id_, - request.offset_message_id_, request.limit_); + CREATE_REQUEST(SearchMessagesRequest, FolderId(request.chat_list_), request.chat_list_ == nullptr, + std::move(request.query_), request.offset_date_, request.offset_chat_id_, request.offset_message_id_, + request.limit_); } void Td::on_request(uint64 id, td_api::searchCallMessages &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 99764ff1a..0ddbfcc8e 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1709,7 +1709,7 @@ class CliClient final : public Actor { send_request(td_api::make_object( search_chat_id_, "", 0, 0, 0, 100, td_api::make_object())); - } else if (op == "Search") { + } else if (op == "Search" || op == "SearchA" || op == "SearchM") { string from_date; string limit; string query; @@ -1719,8 +1719,15 @@ class CliClient final : public Actor { if (from_date.empty()) { from_date = "0"; } - send_request(td_api::make_object(query, to_integer(from_date), 2147482647, 0, - to_integer(limit))); + td_api::object_ptr chat_list; + if (op == "SearchA") { + chat_list = td_api::make_object(); + } + if (op == "SearchM") { + chat_list = td_api::make_object(); + } + send_request(td_api::make_object( + std::move(chat_list), query, to_integer(from_date), 2147482647, 0, to_integer(limit))); } else if (op == "SCM") { string chat_id; string limit;