Simplify searchMessages usage.
This commit is contained in:
parent
9768637010
commit
3080f64273
@ -5772,14 +5772,12 @@ searchChatMessages chat_id:int53 query:string sender_id:MessageSender from_messa
|
|||||||
//-For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
|
//-For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
|
||||||
//@chat_list Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
|
//@chat_list Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
|
||||||
//@query Query to search for
|
//@query Query to search for
|
||||||
//@offset_date The date of the message starting from which the results need to be fetched. Use 0 or any date in the future to get results from the last message
|
//@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
|
||||||
//@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. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
|
//@limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
|
||||||
//@filter Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, searchMessagesFilterFailedToSend, and searchMessagesFilterPinned are unsupported in this function
|
//@filter Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, searchMessagesFilterFailedToSend, and searchMessagesFilterPinned are unsupported in this function
|
||||||
//@min_date If not 0, the minimum date of the messages to return
|
//@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
|
//@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;
|
searchMessages chat_list:ChatList query:string offset:string limit:int32 filter:SearchMessagesFilter min_date:int32 max_date:int32 = FoundMessages;
|
||||||
|
|
||||||
//@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 TDLib
|
//@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 TDLib
|
||||||
//@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats
|
//@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats
|
||||||
|
@ -10500,10 +10500,21 @@ void MessagesManager::on_get_messages_search_result(const string &query, int32 o
|
|||||||
auto it = found_messages_.find(random_id);
|
auto it = found_messages_.find(random_id);
|
||||||
CHECK(it != found_messages_.end());
|
CHECK(it != found_messages_.end());
|
||||||
|
|
||||||
auto &result = it->second.second;
|
auto &result = it->second.full_message_ids;
|
||||||
CHECK(result.empty());
|
CHECK(result.empty());
|
||||||
|
int32 last_message_date = 0;
|
||||||
|
MessageId last_message_id;
|
||||||
|
DialogId last_dialog_id;
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
|
auto message_date = get_message_date(message);
|
||||||
|
auto message_id = MessageId::get_message_id(message, false);
|
||||||
auto dialog_id = DialogId::get_message_dialog_id(message);
|
auto dialog_id = DialogId::get_message_dialog_id(message);
|
||||||
|
if (message_date > 0 && message_id.is_valid() && dialog_id.is_valid()) {
|
||||||
|
last_message_date = message_date;
|
||||||
|
last_message_id = message_id;
|
||||||
|
last_dialog_id = dialog_id;
|
||||||
|
}
|
||||||
|
|
||||||
auto new_full_message_id = on_get_message(std::move(message), false, dialog_id.get_type() == DialogType::Channel,
|
auto new_full_message_id = on_get_message(std::move(message), false, dialog_id.get_type() == DialogType::Channel,
|
||||||
false, false, false, "search messages");
|
false, false, false, "search messages");
|
||||||
if (new_full_message_id != FullMessageId()) {
|
if (new_full_message_id != FullMessageId()) {
|
||||||
@ -10518,7 +10529,11 @@ void MessagesManager::on_get_messages_search_result(const string &query, int32 o
|
|||||||
<< " messages";
|
<< " messages";
|
||||||
total_count = static_cast<int32>(result.size());
|
total_count = static_cast<int32>(result.size());
|
||||||
}
|
}
|
||||||
it->second.first = total_count;
|
it->second.total_count = total_count;
|
||||||
|
if (!result.empty()) {
|
||||||
|
it->second.next_offset = PSTRING() << last_message_date << ',' << last_dialog_id.get() << ','
|
||||||
|
<< last_message_id.get_server_message_id().get();
|
||||||
|
}
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23753,10 +23768,11 @@ void MessagesManager::on_message_db_calls_result(Result<MessageDbCallsResult> re
|
|||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
|
MessagesManager::FoundMessages MessagesManager::search_messages(FolderId folder_id, bool ignore_folder_id,
|
||||||
FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, DialogId offset_dialog_id,
|
const string &query, const string &offset, int32 limit,
|
||||||
MessageId offset_message_id, int32 limit, MessageSearchFilter filter, int32 min_date, int32 max_date,
|
MessageSearchFilter filter, int32 min_date,
|
||||||
int64 &random_id, Promise<Unit> &&promise) {
|
int32 max_date, int64 &random_id,
|
||||||
|
Promise<Unit> &&promise) {
|
||||||
if (random_id != 0) {
|
if (random_id != 0) {
|
||||||
// request has already been sent before
|
// request has already been sent before
|
||||||
auto it = found_messages_.find(random_id);
|
auto it = found_messages_.find(random_id);
|
||||||
@ -23775,19 +23791,36 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
|
|||||||
limit = MAX_SEARCH_MESSAGES;
|
limit = MAX_SEARCH_MESSAGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset_date <= 0) {
|
int32 offset_date = std::numeric_limits<int32>::max();
|
||||||
offset_date = std::numeric_limits<int32>::max();
|
DialogId offset_dialog_id;
|
||||||
|
MessageId offset_message_id;
|
||||||
|
bool is_offset_valid = [&] {
|
||||||
|
if (offset.empty()) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (!offset_message_id.is_valid()) {
|
|
||||||
if (offset_message_id.is_valid_scheduled()) {
|
auto parts = full_split(offset, ',');
|
||||||
promise.set_error(Status::Error(400, "Parameter offset_message_id can't be a scheduled message identifier"));
|
if (parts.size() != 3) {
|
||||||
return {};
|
return false;
|
||||||
}
|
}
|
||||||
offset_message_id = MessageId();
|
auto r_offset_date = to_integer_safe<int32>(parts[0]);
|
||||||
|
auto r_offset_dialog_id = to_integer_safe<int64>(parts[1]);
|
||||||
|
auto r_offset_message_id = to_integer_safe<int32>(parts[2]);
|
||||||
|
if (r_offset_date.is_error() || r_offset_date.ok() <= 0 || r_offset_message_id.is_error() ||
|
||||||
|
r_offset_dialog_id.is_error()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (offset_message_id != MessageId() && !offset_message_id.is_server()) {
|
offset_date = r_offset_date.ok();
|
||||||
promise.set_error(
|
offset_message_id = MessageId(ServerMessageId(r_offset_message_id.ok()));
|
||||||
Status::Error(400, "Parameter offset_message_id must be identifier of the last found message or 0"));
|
offset_dialog_id = DialogId(r_offset_dialog_id.ok());
|
||||||
|
if (!offset_message_id.is_valid() || !offset_dialog_id.is_valid() ||
|
||||||
|
MessagesManager::get_input_peer_force(offset_dialog_id)->get_id() == telegram_api::inputPeerEmpty::ID) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
if (!is_offset_valid) {
|
||||||
|
promise.set_error(Status::Error(400, "Invalid offset specified"));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23809,8 +23842,8 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_messages(
|
|||||||
} while (random_id == 0 || found_messages_.count(random_id) > 0);
|
} while (random_id == 0 || found_messages_.count(random_id) > 0);
|
||||||
found_messages_[random_id]; // reserve place for result
|
found_messages_[random_id]; // reserve place for result
|
||||||
|
|
||||||
LOG(DEBUG) << "Search all messages filtered by " << filter << " with query = \"" << query << "\" from date "
|
LOG(DEBUG) << "Search all messages filtered by " << filter << " with query = \"" << query << "\" from offset "
|
||||||
<< offset_date << ", " << offset_dialog_id << ", " << offset_message_id << " and limit " << limit;
|
<< offset << " and limit " << limit;
|
||||||
|
|
||||||
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise))
|
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise))
|
||||||
->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter,
|
->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter,
|
||||||
|
@ -766,11 +766,9 @@ class MessagesManager final : public Actor {
|
|||||||
FoundMessages offline_search_messages(DialogId dialog_id, const string &query, string offset, int32 limit,
|
FoundMessages offline_search_messages(DialogId dialog_id, const string &query, string offset, int32 limit,
|
||||||
MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise);
|
MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise);
|
||||||
|
|
||||||
std::pair<int32, vector<FullMessageId>> search_messages(FolderId folder_id, bool ignore_folder_id,
|
FoundMessages search_messages(FolderId folder_id, bool ignore_folder_id, const string &query, const string &offset,
|
||||||
const string &query, int32 offset_date,
|
int32 limit, MessageSearchFilter filter, int32 min_date, int32 max_date,
|
||||||
DialogId offset_dialog_id, MessageId offset_message_id,
|
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,
|
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);
|
int64 &random_id, bool use_db, Promise<Unit> &&promise);
|
||||||
@ -3553,8 +3551,7 @@ class MessagesManager final : public Actor {
|
|||||||
FlatHashMap<int64, std::pair<int32, vector<MessageId>>>
|
FlatHashMap<int64, std::pair<int32, vector<MessageId>>>
|
||||||
found_dialog_messages_; // random_id -> [total_count, [message_id]...]
|
found_dialog_messages_; // random_id -> [total_count, [message_id]...]
|
||||||
FlatHashMap<int64, DialogId> found_dialog_messages_dialog_id_; // random_id -> dialog_id
|
FlatHashMap<int64, DialogId> found_dialog_messages_dialog_id_; // random_id -> dialog_id
|
||||||
FlatHashMap<int64, std::pair<int32, vector<FullMessageId>>>
|
FlatHashMap<int64, FoundMessages> found_messages_; // random_id -> FoundMessages
|
||||||
found_messages_; // random_id -> [total_count, [full_message_id]...]
|
|
||||||
FlatHashMap<int64, std::pair<int32, vector<FullMessageId>>>
|
FlatHashMap<int64, std::pair<int32, vector<FullMessageId>>>
|
||||||
found_call_messages_; // random_id -> [total_count, [full_message_id]...]
|
found_call_messages_; // random_id -> [total_count, [full_message_id]...]
|
||||||
|
|
||||||
|
@ -1422,32 +1422,27 @@ class SearchMessagesRequest final : public RequestActor<> {
|
|||||||
FolderId folder_id_;
|
FolderId folder_id_;
|
||||||
bool ignore_folder_id_;
|
bool ignore_folder_id_;
|
||||||
string query_;
|
string query_;
|
||||||
int32 offset_date_;
|
string offset_;
|
||||||
DialogId offset_dialog_id_;
|
|
||||||
MessageId offset_message_id_;
|
|
||||||
int32 limit_;
|
int32 limit_;
|
||||||
MessageSearchFilter filter_;
|
MessageSearchFilter filter_;
|
||||||
int32 min_date_;
|
int32 min_date_;
|
||||||
int32 max_date_;
|
int32 max_date_;
|
||||||
int64 random_id_;
|
int64 random_id_;
|
||||||
|
|
||||||
std::pair<int32, vector<FullMessageId>> messages_;
|
MessagesManager::FoundMessages messages_;
|
||||||
|
|
||||||
void do_run(Promise<Unit> &&promise) final {
|
void do_run(Promise<Unit> &&promise) final {
|
||||||
messages_ = td_->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_date_,
|
messages_ = td_->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_, limit_, filter_,
|
||||||
offset_dialog_id_, offset_message_id_, limit_, filter_,
|
|
||||||
min_date_, max_date_, random_id_, std::move(promise));
|
min_date_, max_date_, random_id_, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_send_result() final {
|
void do_send_result() final {
|
||||||
send_result(
|
send_result(td_->messages_manager_->get_found_messages_object(messages_, "SearchMessagesRequest"));
|
||||||
td_->messages_manager_->get_messages_object(messages_.first, messages_.second, true, "SearchMessagesRequest"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_send_error(Status &&status) final {
|
void do_send_error(Status &&status) final {
|
||||||
if (status.message() == "SEARCH_QUERY_EMPTY") {
|
if (status.message() == "SEARCH_QUERY_EMPTY") {
|
||||||
messages_.first = 0;
|
messages_ = {};
|
||||||
messages_.second.clear();
|
|
||||||
return do_send_result();
|
return do_send_result();
|
||||||
}
|
}
|
||||||
send_error(std::move(status));
|
send_error(std::move(status));
|
||||||
@ -1455,15 +1450,13 @@ class SearchMessagesRequest final : public RequestActor<> {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query,
|
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,
|
string offset, int32 limit, tl_object_ptr<td_api::SearchMessagesFilter> &&filter,
|
||||||
tl_object_ptr<td_api::SearchMessagesFilter> &&filter, int32 min_date, int32 max_date)
|
int32 min_date, int32 max_date)
|
||||||
: RequestActor(std::move(td), request_id)
|
: RequestActor(std::move(td), request_id)
|
||||||
, folder_id_(folder_id)
|
, folder_id_(folder_id)
|
||||||
, ignore_folder_id_(ignore_folder_id)
|
, ignore_folder_id_(ignore_folder_id)
|
||||||
, query_(std::move(query))
|
, query_(std::move(query))
|
||||||
, offset_date_(offset_date)
|
, offset_(std::move(offset))
|
||||||
, offset_dialog_id_(offset_dialog_id)
|
|
||||||
, offset_message_id_(offset_message_id)
|
|
||||||
, limit_(limit)
|
, limit_(limit)
|
||||||
, filter_(get_message_search_filter(filter))
|
, filter_(get_message_search_filter(filter))
|
||||||
, min_date_(min_date)
|
, min_date_(min_date)
|
||||||
@ -5161,13 +5154,14 @@ 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_);
|
||||||
|
CLEAN_INPUT_STRING(request.offset_);
|
||||||
DialogListId dialog_list_id(request.chat_list_);
|
DialogListId dialog_list_id(request.chat_list_);
|
||||||
if (!dialog_list_id.is_folder()) {
|
if (!dialog_list_id.is_folder()) {
|
||||||
return send_error_raw(id, 400, "Wrong chat list specified");
|
return send_error_raw(id, 400, "Wrong chat list specified");
|
||||||
}
|
}
|
||||||
CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr,
|
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_,
|
std::move(request.query_), std::move(request.offset_), request.limit_, std::move(request.filter_),
|
||||||
request.limit_, std::move(request.filter_), request.min_date_, request.max_date_);
|
request.min_date_, request.max_date_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::searchCallMessages &request) {
|
void Td::on_request(uint64 id, const td_api::searchCallMessages &request) {
|
||||||
|
@ -2318,8 +2318,8 @@ class CliClient final : public Actor {
|
|||||||
string query;
|
string query;
|
||||||
string limit;
|
string limit;
|
||||||
string filter;
|
string filter;
|
||||||
int32 from_date;
|
string offset;
|
||||||
get_args(args, query, limit, filter, from_date);
|
get_args(args, query, limit, filter, offset);
|
||||||
td_api::object_ptr<td_api::ChatList> chat_list;
|
td_api::object_ptr<td_api::ChatList> chat_list;
|
||||||
if (op == "SearchA") {
|
if (op == "SearchA") {
|
||||||
chat_list = td_api::make_object<td_api::chatListArchive>();
|
chat_list = td_api::make_object<td_api::chatListArchive>();
|
||||||
@ -2327,9 +2327,8 @@ class CliClient final : public Actor {
|
|||||||
if (op == "SearchM") {
|
if (op == "SearchM") {
|
||||||
chat_list = td_api::make_object<td_api::chatListMain>();
|
chat_list = td_api::make_object<td_api::chatListMain>();
|
||||||
}
|
}
|
||||||
send_request(td_api::make_object<td_api::searchMessages>(std::move(chat_list), query, from_date, 2147483647, 0,
|
send_request(td_api::make_object<td_api::searchMessages>(std::move(chat_list), query, offset, as_limit(limit),
|
||||||
as_limit(limit), as_search_messages_filter(filter), 1,
|
as_search_messages_filter(filter), 1, 2147483647));
|
||||||
2147483647));
|
|
||||||
} else if (op == "SCM") {
|
} else if (op == "SCM") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
SearchQuery query;
|
SearchQuery query;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user