Add min_date/max_date to searchMessages.

GitOrigin-RevId: a340969e431dd2de018461f3904da6569a91b166
This commit is contained in:
levlam 2020-09-08 14:58:02 +03:00
parent 1a6ca88777
commit 0540ae7b60
6 changed files with 31 additions and 19 deletions

View File

@ -3622,7 +3622,9 @@ searchChatMessages chat_id:int53 query:string sender_user_id:int32 from_message_
//@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
//@filter Filter for message content in the search results; searchMessagesFilterCall, searchMessagesFilterMissedCall, searchMessagesFilterMention, searchMessagesFilterUnreadMention and searchMessagesFilterFailedToSend are unsupported in this function
searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 filter:SearchMessagesFilter = Messages;
//@min_date If not 0, the minimum date of the messages to return
//@max_date If not 0, the maximum date of the messages to return
searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id:int53 offset_message_id:int53 limit:int32 filter:SearchMessagesFilter min_date:int32 max_date: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

Binary file not shown.

View File

@ -1661,6 +1661,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
MessageId offset_message_id_;
int32 limit_;
MessageSearchFilter filter_;
int32 min_date_;
int32 max_date_;
int64 random_id_;
public:
@ -1669,7 +1671,7 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
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, MessageSearchFilter filter,
int64 random_id) {
int32 min_date, int32 max_date, int64 random_id) {
query_ = query;
offset_date_ = offset_date;
offset_dialog_id_ = offset_dialog_id;
@ -1677,6 +1679,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
limit_ = limit;
random_id_ = random_id;
filter_ = filter;
min_date_ = min_date;
max_date_ = max_date;
auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id);
CHECK(input_peer != nullptr);
@ -1686,8 +1690,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal(
flags, folder_id.get(), query, get_input_messages_filter(filter), 0, 0, offset_date_, std::move(input_peer),
offset_message_id.get_server_message_id().get(), limit)));
flags, folder_id.get(), query, get_input_messages_filter(filter), min_date_, max_date_, offset_date_,
std::move(input_peer), offset_message_id.get_server_message_id().get(), limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -1698,8 +1702,8 @@ class SearchMessagesGlobalQuery : public Td::ResultHandler {
auto info = td->messages_manager_->on_get_messages(result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
td->messages_manager_->on_get_messages_search_result(query_, offset_date_, offset_dialog_id_, offset_message_id_,
limit_, filter_, random_id_, info.total_count,
std::move(info.messages));
limit_, filter_, min_date_, max_date_, random_id_,
info.total_count, std::move(info.messages));
promise_.set_value(Unit());
}
@ -8794,7 +8798,8 @@ void MessagesManager::on_failed_dialog_messages_search(DialogId dialog_id, int64
void MessagesManager::on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit,
MessageSearchFilter filter, int64 random_id, int32 total_count,
MessageSearchFilter filter, int32 min_date, int32 max_date,
int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages) {
LOG(INFO) << "Receive " << messages.size() << " found messages";
auto it = found_messages_.find(random_id);
@ -19300,7 +19305,8 @@ void MessagesManager::on_messages_db_calls_result(Result<MessagesDbCallsResult>
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,
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise) {
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, int32 min_date, int32 max_date,
int64 &random_id, Promise<Unit> &&promise) {
if (random_id != 0) {
// request has already been sent before
auto it = found_messages_.find(random_id);
@ -19357,7 +19363,7 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise))
->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter,
random_id);
min_date, max_date, random_id);
return {};
}

View File

@ -240,7 +240,7 @@ class MessagesManager : public Actor {
void on_get_messages_search_result(const string &query, int32 offset_date, DialogId offset_dialog_id,
MessageId offset_message_id, int32 limit, MessageSearchFilter filter,
int64 random_id, int32 total_count,
int32 min_date, int32 max_date, int64 random_id, int32 total_count,
vector<tl_object_ptr<telegram_api::Message>> &&messages);
void on_failed_messages_search(int64 random_id);
@ -678,8 +678,8 @@ class MessagesManager : public Actor {
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,
int32 limit, MessageSearchFilter filter, int64 &random_id,
Promise<Unit> &&promise);
int32 limit, MessageSearchFilter filter, int32 min_date,
int32 max_date, int64 &random_id, Promise<Unit> &&promise);
std::pair<int32, vector<FullMessageId>> search_call_messages(MessageId from_message_id, int32 limit, bool only_missed,
int64 &random_id, bool use_db, Promise<Unit> &&promise);

View File

@ -1481,14 +1481,16 @@ class SearchMessagesRequest : public RequestActor<> {
MessageId offset_message_id_;
int32 limit_;
MessageSearchFilter filter_;
int32 min_date_;
int32 max_date_;
int64 random_id_;
std::pair<int32, vector<FullMessageId>> messages_;
void do_run(Promise<Unit> &&promise) override {
messages_ =
td->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_date_, offset_dialog_id_,
offset_message_id_, limit_, filter_, 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_, filter_,
min_date_, max_date_, random_id_, std::move(promise));
}
void do_send_result() override {
@ -1507,7 +1509,7 @@ class SearchMessagesRequest : public RequestActor<> {
public:
SearchMessagesRequest(ActorShared<Td> 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,
tl_object_ptr<td_api::SearchMessagesFilter> &&filter)
tl_object_ptr<td_api::SearchMessagesFilter> &&filter, int32 min_date, int32 max_date)
: RequestActor(std::move(td), request_id)
, folder_id_(folder_id)
, ignore_folder_id_(ignore_folder_id)
@ -1517,6 +1519,8 @@ class SearchMessagesRequest : public RequestActor<> {
, offset_message_id_(offset_message_id)
, limit_(limit)
, filter_(get_message_search_filter(filter))
, min_date_(min_date)
, max_date_(max_date)
, random_id_(0) {
}
};
@ -5482,7 +5486,7 @@ void Td::on_request(uint64 id, td_api::searchMessages &request) {
}
CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr,
std::move(request.query_), request.offset_date_, request.offset_chat_id_, request.offset_message_id_,
request.limit_, std::move(request.filter_));
request.limit_, std::move(request.filter_), request.min_date_, request.max_date_);
}
void Td::on_request(uint64 id, td_api::searchCallMessages &request) {

View File

@ -1885,8 +1885,8 @@ class CliClient final : public Actor {
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),
as_search_messages_filter(filter)));
std::move(chat_list), query, to_integer<int32>(from_date), 2147483647, 0, to_integer<int32>(limit),
as_search_messages_filter(filter), 1, 2147483647));
} else if (op == "SCM") {
string chat_id;
string limit;