Add getChatSparseMessagePositions.saved_messages_topic.

This commit is contained in:
levlam 2024-01-16 14:12:57 +03:00
parent f76c384f90
commit 16fc47fb88
5 changed files with 31 additions and 16 deletions

View File

@ -7247,7 +7247,8 @@ getChatMessageByDate chat_id:int53 date:int32 = Message;
//@filter Filter for message content. Filters searchMessagesFilterEmpty, searchMessagesFilterMention, searchMessagesFilterUnreadMention, and searchMessagesFilterUnreadReaction are unsupported in this function
//@from_message_id The message identifier from which to return information about message positions
//@limit The expected number of message positions to be returned; 50-2000. A smaller number of positions can be returned, if there are not enough appropriate messages
getChatSparseMessagePositions chat_id:int53 filter:SearchMessagesFilter from_message_id:int53 limit:int32 = MessagePositions;
//@saved_messages_topic If not null, only messages in the specified Saved Messages topic will be considered; pass null to consider all messages, or for chats other than Saved Messages
getChatSparseMessagePositions chat_id:int53 filter:SearchMessagesFilter from_message_id:int53 limit:int32 saved_messages_topic:SavedMessagesTopic = MessagePositions;
//@description Returns information about the next messages of the specified type in the chat split by days. Returns the results in reverse chronological order. Can return partial result for the last returned day. Behavior of this method depends on the value of the option "utc_time_offset"
//@chat_id Identifier of the chat in which to return information about messages

View File

@ -1879,6 +1879,7 @@ class SearchMessagesQuery final : public Td::ResultHandler {
class GetSearchResultPositionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::messagePositions>> promise_;
DialogId dialog_id_;
SavedMessagesTopicId saved_messages_topic_id_;
MessageSearchFilter filter_;
public:
@ -1886,17 +1887,25 @@ class GetSearchResultPositionsQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id, MessageSearchFilter filter, MessageId from_message_id, int32 limit) {
void send(DialogId dialog_id, SavedMessagesTopicId saved_messages_topic_id, MessageSearchFilter filter,
MessageId from_message_id, int32 limit) {
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise_.set_error(Status::Error(400, "Can't access the chat"));
}
dialog_id_ = dialog_id;
saved_messages_topic_id_ = saved_messages_topic_id;
filter_ = filter;
int32 flags = 0;
telegram_api::object_ptr<telegram_api::InputPeer> saved_input_peer;
if (saved_messages_topic_id.is_valid()) {
flags |= telegram_api::messages_getSearchResultsPositions::SAVED_PEER_ID_MASK;
saved_input_peer = saved_messages_topic_id.get_input_peer(td_);
CHECK(saved_input_peer != nullptr);
}
send_query(G()->net_query_creator().create(telegram_api::messages_getSearchResultsPositions(
flags, std::move(input_peer), nullptr, get_input_messages_filter(filter),
flags, std::move(input_peer), std::move(saved_input_peer), get_input_messages_filter(filter),
from_message_id.get_server_message_id().get(), limit)));
}
@ -1906,8 +1915,8 @@ class GetSearchResultPositionsQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error());
}
td_->messages_manager_->on_get_dialog_sparse_message_positions(dialog_id_, filter_, result_ptr.move_as_ok(),
std::move(promise_));
td_->messages_manager_->on_get_dialog_sparse_message_positions(dialog_id_, saved_messages_topic_id_, filter_,
result_ptr.move_as_ok(), std::move(promise_));
}
void on_error(Status status) final {
@ -21147,8 +21156,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_dialog_message_by_date_objec
}
void MessagesManager::get_dialog_sparse_message_positions(
DialogId dialog_id, MessageSearchFilter filter, MessageId from_message_id, int32 limit,
Promise<td_api::object_ptr<td_api::messagePositions>> &&promise) {
DialogId dialog_id, SavedMessagesTopicId saved_messages_topic_id, MessageSearchFilter filter,
MessageId from_message_id, int32 limit, Promise<td_api::object_ptr<td_api::messagePositions>> &&promise) {
const Dialog *d = get_dialog_force(dialog_id, "get_dialog_sparse_message_positions");
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
@ -21176,8 +21185,12 @@ void MessagesManager::get_dialog_sparse_message_positions(
} else {
from_message_id = from_message_id.get_next_server_message_id();
}
TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, dialog_id));
if (filter == MessageSearchFilter::FailedToSend || dialog_id.get_type() == DialogType::SecretChat) {
if (saved_messages_topic_id.is_valid()) {
return promise.set_value(td_api::make_object<td_api::messagePositions>());
}
if (!G()->use_message_database()) {
return promise.set_error(Status::Error(400, "Unsupported without message database"));
}
@ -21211,7 +21224,7 @@ void MessagesManager::get_dialog_sparse_message_positions(
case DialogType::Chat:
case DialogType::Channel:
td_->create_handler<GetSearchResultPositionsQuery>(std::move(promise))
->send(dialog_id, filter, from_message_id, limit);
->send(dialog_id, saved_messages_topic_id, filter, from_message_id, limit);
break;
case DialogType::SecretChat:
case DialogType::None:
@ -21221,7 +21234,7 @@ void MessagesManager::get_dialog_sparse_message_positions(
}
void MessagesManager::on_get_dialog_sparse_message_positions(
DialogId dialog_id, MessageSearchFilter filter,
DialogId dialog_id, SavedMessagesTopicId saved_messages_topic_id, MessageSearchFilter filter,
telegram_api::object_ptr<telegram_api::messages_searchResultsPositions> positions,
Promise<td_api::object_ptr<td_api::messagePositions>> &&promise) {
auto message_positions = transform(

View File

@ -736,12 +736,12 @@ class MessagesManager final : public Actor {
void on_get_dialog_message_by_date_fail(int64 random_id);
void get_dialog_sparse_message_positions(DialogId dialog_id, MessageSearchFilter filter, MessageId from_message_id,
int32 limit,
void get_dialog_sparse_message_positions(DialogId dialog_id, SavedMessagesTopicId saved_messages_topic_id,
MessageSearchFilter filter, MessageId from_message_id, int32 limit,
Promise<td_api::object_ptr<td_api::messagePositions>> &&promise);
void on_get_dialog_sparse_message_positions(
DialogId dialog_id, MessageSearchFilter filter,
static void on_get_dialog_sparse_message_positions(
DialogId dialog_id, SavedMessagesTopicId saved_messages_topic_id, MessageSearchFilter filter,
telegram_api::object_ptr<telegram_api::messages_searchResultsPositions> positions,
Promise<td_api::object_ptr<td_api::messagePositions>> &&promise);

View File

@ -5285,8 +5285,9 @@ void Td::on_request(uint64 id, const td_api::getChatSparseMessagePositions &requ
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
messages_manager_->get_dialog_sparse_message_positions(
DialogId(request.chat_id_), get_message_search_filter(request.filter_), MessageId(request.from_message_id_),
request.limit_, std::move(promise));
DialogId(request.chat_id_), SavedMessagesTopicId(this, request.saved_messages_topic_),
get_message_search_filter(request.filter_), MessageId(request.from_message_id_), request.limit_,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatMessageCount &request) {

View File

@ -2948,7 +2948,7 @@ class CliClient final : public Actor {
string limit;
get_args(args, chat_id, filter, from_message_id, limit);
send_request(td_api::make_object<td_api::getChatSparseMessagePositions>(
chat_id, as_search_messages_filter(filter), from_message_id, as_limit(limit)));
chat_id, as_search_messages_filter(filter), from_message_id, as_limit(limit), get_saved_messages_topic()));
} else if (op == "gcmc") {
ChatId chat_id;
string filter;