Add chat_list filter to searchMessages.

GitOrigin-RevId: 3dbc4b3509545f3c23f0231c931af0a73bef8796
This commit is contained in:
levlam 2019-10-22 15:06:11 +03:00
parent 0e874a5247
commit ca35608868
6 changed files with 36 additions and 16 deletions

View File

@ -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)). //@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 //-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 //@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_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_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 //@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 //@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 //@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 //@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

Binary file not shown.

View File

@ -1451,8 +1451,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
explicit SearchMessagesGlobalQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SearchMessagesGlobalQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(const string &query, int32 offset_date, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, void send(FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date,
int64 random_id) { DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, int64 random_id) {
query_ = query; query_ = query;
offset_date_ = offset_date; offset_date_ = offset_date;
offset_dialog_id_ = offset_dialog_id; offset_dialog_id_ = offset_dialog_id;
@ -1465,8 +1465,12 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
input_peer = make_tl_object<telegram_api::inputPeerEmpty>(); input_peer = make_tl_object<telegram_api::inputPeerEmpty>();
} }
int32 flags = 0;
if (!ignore_folder_id) {
flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK;
}
send_query(G()->net_query_creator().create(create_storer( 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)))); offset_message_id.get_server_message_id().get(), limit))));
} }
@ -15728,7 +15732,8 @@ void MessagesManager::on_messages_db_calls_result(Result<MessagesDbCallsResult>
promise.set_value(Unit()); promise.set_value(Unit());
} }
std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(const string &query, int32 offset_date, std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(FolderId folder_id, bool ignore_folder_id,
const string &query, int32 offset_date,
DialogId offset_dialog_id, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageId offset_message_id, int32 limit,
int64 &random_id, Promise<Unit> &&promise) { int64 &random_id, Promise<Unit> &&promise) {
@ -15777,7 +15782,7 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(const s
<< offset_dialog_id << ", " << offset_message_id << " and with limit " << limit; << offset_dialog_id << ", " << offset_message_id << " and with limit " << limit;
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise)) td_->create_handler<SearchMessagesGlobalQuery>(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; return result;
} }

View File

@ -598,7 +598,8 @@ class MessagesManager : public Actor {
DialogId dialog_id, const string &query, int64 from_search_id, int32 limit, DialogId dialog_id, const string &query, int64 from_search_id, int32 limit,
const tl_object_ptr<td_api::SearchMessagesFilter> &filter, int64 &random_id, Promise<> &&promise); const tl_object_ptr<td_api::SearchMessagesFilter> &filter, int64 &random_id, Promise<> &&promise);
std::pair<int32, vector<FullMessageId>> search_messages(const string &query, int32 offset_date, std::pair<int32, vector<FullMessageId>> search_messages(FolderId folder_id, bool ignore_folder_id,
const string &query, int32 offset_date,
DialogId offset_dialog_id, MessageId offset_message_id, DialogId offset_dialog_id, MessageId offset_message_id,
int32 limit, int64 &random_id, Promise<Unit> &&promise); int32 limit, int64 &random_id, Promise<Unit> &&promise);

View File

@ -1530,6 +1530,8 @@ class OfflineSearchMessagesRequest : public RequestActor<> {
}; };
class SearchMessagesRequest : public RequestActor<> { class SearchMessagesRequest : public RequestActor<> {
FolderId folder_id_;
bool ignore_folder_id_;
string query_; string query_;
int32 offset_date_; int32 offset_date_;
DialogId offset_dialog_id_; DialogId offset_dialog_id_;
@ -1540,8 +1542,9 @@ class SearchMessagesRequest : public RequestActor<> {
std::pair<int32, vector<FullMessageId>> messages_; std::pair<int32, vector<FullMessageId>> messages_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
messages_ = td->messages_manager_->search_messages(query_, offset_date_, offset_dialog_id_, offset_message_id_, messages_ =
limit_, random_id_, std::move(promise)); 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 { void do_send_result() override {
@ -1558,9 +1561,11 @@ class SearchMessagesRequest : public RequestActor<> {
} }
public: public:
SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, string query, int32 offset_date, int64 offset_dialog_id, SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query,
int64 offset_message_id, int32 limit) int32 offset_date, int64 offset_dialog_id, int64 offset_message_id, int32 limit)
: RequestActor(std::move(td), request_id) : RequestActor(std::move(td), request_id)
, folder_id_(folder_id)
, ignore_folder_id_(ignore_folder_id)
, query_(std::move(query)) , query_(std::move(query))
, offset_date_(offset_date) , offset_date_(offset_date)
, offset_dialog_id_(offset_dialog_id) , 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) { void Td::on_request(uint64 id, td_api::searchMessages &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_); CLEAN_INPUT_STRING(request.query_);
CREATE_REQUEST(SearchMessagesRequest, std::move(request.query_), request.offset_date_, request.offset_chat_id_, CREATE_REQUEST(SearchMessagesRequest, FolderId(request.chat_list_), request.chat_list_ == nullptr,
request.offset_message_id_, request.limit_); 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) { void Td::on_request(uint64 id, td_api::searchCallMessages &request) {

View File

@ -1709,7 +1709,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
search_chat_id_, "", 0, 0, 0, 100, td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>())); search_chat_id_, "", 0, 0, 0, 100, td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>()));
} else if (op == "Search") { } else if (op == "Search" || op == "SearchA" || op == "SearchM") {
string from_date; string from_date;
string limit; string limit;
string query; string query;
@ -1719,8 +1719,15 @@ class CliClient final : public Actor {
if (from_date.empty()) { if (from_date.empty()) {
from_date = "0"; from_date = "0";
} }
send_request(td_api::make_object<td_api::searchMessages>(query, to_integer<int32>(from_date), 2147482647, 0, td_api::object_ptr<td_api::ChatList> chat_list;
to_integer<int32>(limit))); if (op == "SearchA") {
chat_list = td_api::make_object<td_api::chatListArchive>();
}
if (op == "SearchM") {
chat_list = td_api::make_object<td_api::chatListMain>();
}
send_request(td_api::make_object<td_api::searchMessages>(
std::move(chat_list), query, to_integer<int32>(from_date), 2147482647, 0, to_integer<int32>(limit)));
} else if (op == "SCM") { } else if (op == "SCM") {
string chat_id; string chat_id;
string limit; string limit;