Add td_api::searchOutgoingDocumentMessages.

This commit is contained in:
levlam 2022-02-22 15:58:16 +03:00
parent 867c95bdb2
commit 4e1f2cbf8b
6 changed files with 100 additions and 4 deletions

View File

@ -4439,9 +4439,15 @@ searchSecretMessages chat_id:int53 query:string offset:string limit:int32 filter
//@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 TDLib
//@from_message_id Identifier of the message from which to search; use 0 to get results from the last message
//@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 @only_missed If true, returns only messages with missed/declined calls
//@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
//@only_missed If true, returns only messages with missed/declined calls
searchCallMessages from_message_id:int53 limit:int32 only_missed:Bool = Messages;
//@description Searches for outgoing messages with content of the type messageDocument in all chats except secret chats. Returns the results in reverse chronological order
//@query Query to search for in document file name and message caption
//@limit The maximum number of messages to be returned; up to 100
searchOutgoingDocumentMessages query:string limit:int32 = FoundMessages;
//@description Deletes all call messages @revoke Pass true to delete the messages for all users
deleteAllCallMessages revoke:Bool = Ok;

View File

@ -2636,6 +2636,45 @@ class GetAllScheduledMessagesQuery final : public Td::ResultHandler {
}
};
class SearchSentMediaQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::foundMessages>> promise_;
public:
explicit SearchSentMediaQuery(Promise<td_api::object_ptr<td_api::foundMessages>> &&promise)
: promise_(std::move(promise)) {
}
void send(const string &query, int32 limit) {
send_query(G()->net_query_creator().create(telegram_api::messages_searchSentMedia(
query, telegram_api::make_object<telegram_api::inputMessagesFilterDocument>(), limit)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_searchSentMedia>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto info = td_->messages_manager_->get_messages_info(result_ptr.move_as_ok(), "SearchSentMediaQuery");
td_->messages_manager_->get_channel_differences_if_needed(
std::move(info),
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
promise = std::move(promise_)](Result<MessagesManager::MessagesInfo> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
auto info = result.move_as_ok();
send_closure(actor_id, &MessagesManager::on_get_outgoing_document_messages, std::move(info.messages),
std::move(promise));
}
}));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetRecentLocationsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::messages>> promise_;
DialogId dialog_id_;
@ -10575,6 +10614,27 @@ void MessagesManager::on_failed_messages_search(int64 random_id) {
found_messages_.erase(it);
}
void MessagesManager::on_get_outgoing_document_messages(vector<tl_object_ptr<telegram_api::Message>> &&messages,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
FoundMessages found_messages;
for (auto &message : messages) {
auto dialog_id = get_message_dialog_id(message);
auto full_message_id = on_get_message(std::move(message), false, dialog_id.get_type() == DialogType::Channel, false,
false, false, "on_get_outgoing_document_messages");
if (full_message_id != FullMessageId()) {
CHECK(dialog_id == full_message_id.get_dialog_id());
found_messages.full_message_ids.push_back(full_message_id);
}
}
auto result = get_found_messages_object(found_messages, "on_get_outgoing_document_messages");
td::remove_if(result->messages_,
[](const auto &message) { return message->content_->get_id() != td_api::messageDocument::ID; });
result->total_count_ = narrow_cast<int32>(result->messages_.size());
promise.set_value(std::move(result));
}
void MessagesManager::on_get_scheduled_server_messages(DialogId dialog_id, uint32 generation,
vector<tl_object_ptr<telegram_api::Message>> &&messages,
bool is_not_modified) {
@ -22746,12 +22806,23 @@ std::pair<int32, vector<FullMessageId>> MessagesManager::search_call_messages(Me
}
}
LOG(DEBUG) << "Search call messages on server from " << from_message_id << " and with limit " << limit;
td_->create_handler<SearchMessagesQuery>(std::move(promise))
->send(DialogId(), "", DialogId(), from_message_id, 0, limit, filter, MessageId(), random_id);
return result;
}
void MessagesManager::search_outgoing_document_messages(const string &query, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise) {
if (limit <= 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
}
if (limit > MAX_SEARCH_MESSAGES) {
limit = MAX_SEARCH_MESSAGES;
}
td_->create_handler<SearchSentMediaQuery>(std::move(promise))->send(query, limit);
}
void MessagesManager::search_dialog_recent_location_messages(DialogId dialog_id, int32 limit,
Promise<td_api::object_ptr<td_api::messages>> &&promise) {
LOG(INFO) << "Search recent location messages in " << dialog_id << " with limit " << limit;

View File

@ -227,6 +227,9 @@ class MessagesManager final : public Actor {
vector<tl_object_ptr<telegram_api::Message>> &&messages, Promise<Unit> &&promise);
void on_failed_messages_search(int64 random_id);
void on_get_outgoing_document_messages(vector<tl_object_ptr<telegram_api::Message>> &&messages,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise);
void on_get_scheduled_server_messages(DialogId dialog_id, uint32 generation,
vector<tl_object_ptr<telegram_api::Message>> &&messages, bool is_not_modified);
@ -764,6 +767,9 @@ class MessagesManager final : public Actor {
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);
void search_outgoing_document_messages(const string &query, int32 limit,
Promise<td_api::object_ptr<td_api::foundMessages>> &&promise);
void search_dialog_recent_location_messages(DialogId dialog_id, int32 limit,
Promise<td_api::object_ptr<td_api::messages>> &&promise);

View File

@ -5220,11 +5220,18 @@ void Td::on_request(uint64 id, td_api::searchMessages &request) {
request.limit_, std::move(request.filter_), request.min_date_, request.max_date_);
}
void Td::on_request(uint64 id, td_api::searchCallMessages &request) {
void Td::on_request(uint64 id, const td_api::searchCallMessages &request) {
CHECK_IS_USER();
CREATE_REQUEST(SearchCallMessagesRequest, request.from_message_id_, request.limit_, request.only_missed_);
}
void Td::on_request(uint64 id, td_api::searchOutgoingDocumentMessages &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_);
CREATE_REQUEST_PROMISE();
messages_manager_->search_outgoing_document_messages(request.query_, request.limit_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteAllCallMessages &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -614,7 +614,9 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::searchMessages &request);
void on_request(uint64 id, td_api::searchCallMessages &request);
void on_request(uint64 id, const td_api::searchCallMessages &request);
void on_request(uint64 id, td_api::searchOutgoingDocumentMessages &request);
void on_request(uint64 id, const td_api::deleteAllCallMessages &request);

View File

@ -2211,6 +2211,10 @@ class CliClient final : public Actor {
bool only_missed;
get_args(args, limit, offset_message_id, only_missed);
send_request(td_api::make_object<td_api::searchCallMessages>(offset_message_id, as_limit(limit), only_missed));
} else if (op == "sodm") {
SearchQuery query;
get_args(args, query);
send_request(td_api::make_object<td_api::searchOutgoingDocumentMessages>(query.query, query.limit));
} else if (op == "DeleteAllCallMessages") {
bool revoke = as_bool(args);
send_request(td_api::make_object<td_api::deleteAllCallMessages>(revoke));