Add getChatMessagePosition.saved_messages_topic.

This commit is contained in:
levlam 2024-01-15 20:39:47 +03:00
parent 7d71562a24
commit 3eba7d4f2b
7 changed files with 60 additions and 18 deletions

View File

@ -7266,7 +7266,8 @@ getChatMessageCount chat_id:int53 filter:SearchMessagesFilter return_local:Bool
//@message_id Message identifier //@message_id Message identifier
//@filter Filter for message content; searchMessagesFilterEmpty, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, and searchMessagesFilterFailedToSend are unsupported in this function //@filter Filter for message content; searchMessagesFilterEmpty, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, and searchMessagesFilterFailedToSend are unsupported in this function
//@message_thread_id If not 0, only messages in the specified thread will be considered; supergroups only //@message_thread_id If not 0, only messages in the specified thread will be considered; supergroups only
getChatMessagePosition chat_id:int53 message_id:int53 filter:SearchMessagesFilter message_thread_id:int53 = Count; //@saved_messages_topic If not null, only messages in the specified Saved Messages topic will be considered; pass null for chats other than Saved Messages or to consider all relevant messages
getChatMessagePosition chat_id:int53 message_id:int53 filter:SearchMessagesFilter message_thread_id:int53 saved_messages_topic:SavedMessagesTopic = Count;
//@description Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id) @chat_id Chat identifier //@description Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id) @chat_id Chat identifier
getChatScheduledMessages chat_id:int53 = Messages; getChatScheduledMessages chat_id:int53 = Messages;

View File

@ -1633,31 +1633,45 @@ class GetMessagePositionQuery final : public Td::ResultHandler {
DialogId dialog_id_; DialogId dialog_id_;
MessageId message_id_; MessageId message_id_;
MessageId top_thread_message_id_; MessageId top_thread_message_id_;
SavedMessagesTopicId saved_messages_topic_id_;
MessageSearchFilter filter_; MessageSearchFilter filter_;
public: public:
explicit GetMessagePositionQuery(Promise<int32> &&promise) : promise_(std::move(promise)) { explicit GetMessagePositionQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
} }
void send(DialogId dialog_id, MessageId message_id, MessageSearchFilter filter, MessageId top_thread_message_id) { void send(DialogId dialog_id, MessageId message_id, MessageSearchFilter filter, MessageId top_thread_message_id,
SavedMessagesTopicId saved_messages_topic_id) {
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
message_id_ = message_id; message_id_ = message_id;
top_thread_message_id_ = top_thread_message_id; top_thread_message_id_ = top_thread_message_id;
saved_messages_topic_id_ = saved_messages_topic_id;
filter_ = filter; filter_ = filter;
if (filter == MessageSearchFilter::Empty && !top_thread_message_id.is_valid()) { if (filter == MessageSearchFilter::Empty && !top_thread_message_id.is_valid()) {
if (saved_messages_topic_id.is_valid()) {
send_query(G()->net_query_creator().create(telegram_api::messages_getHistory(
saved_messages_topic_id.get_input_peer(td_), message_id.get_server_message_id().get(), 0, -1, 1, 0, 0, 0)));
} else {
send_query(G()->net_query_creator().create(telegram_api::messages_getHistory( send_query(G()->net_query_creator().create(telegram_api::messages_getHistory(
std::move(input_peer), message_id.get_server_message_id().get(), 0, -1, 1, 0, 0, 0))); std::move(input_peer), message_id.get_server_message_id().get(), 0, -1, 1, 0, 0, 0)));
}
} else { } else {
int32 flags = 0; int32 flags = 0;
tl_object_ptr<telegram_api::InputPeer> saved_input_peer;
if (saved_messages_topic_id.is_valid()) {
flags |= telegram_api::messages_search::SAVED_PEER_ID_MASK;
saved_input_peer = saved_messages_topic_id.get_input_peer(td_);
CHECK(saved_input_peer != nullptr);
}
if (top_thread_message_id.is_valid()) { if (top_thread_message_id.is_valid()) {
flags |= telegram_api::messages_search::TOP_MSG_ID_MASK; flags |= telegram_api::messages_search::TOP_MSG_ID_MASK;
} }
send_query(G()->net_query_creator().create(telegram_api::messages_search( send_query(G()->net_query_creator().create(telegram_api::messages_search(
flags, std::move(input_peer), string(), nullptr, nullptr, Auto(), flags, std::move(input_peer), string(), nullptr, std::move(saved_input_peer), Auto(),
top_thread_message_id.get_server_message_id().get(), get_input_messages_filter(filter), 0, top_thread_message_id.get_server_message_id().get(), get_input_messages_filter(filter), 0,
std::numeric_limits<int32>::max(), message_id.get_server_message_id().get(), -1, 1, std::numeric_limits<int32>::max(), message_id.get_server_message_id().get(), -1, 1,
std::numeric_limits<int32>::max(), 0, 0))); std::numeric_limits<int32>::max(), 0, 0)));
@ -1689,7 +1703,7 @@ class GetMessagePositionQuery final : public Td::ResultHandler {
} }
if (messages->offset_id_offset_ <= 0) { if (messages->offset_id_offset_ <= 0) {
LOG(ERROR) << "Failed to receive position for " << message_id_ << " in thread of " << top_thread_message_id_ LOG(ERROR) << "Failed to receive position for " << message_id_ << " in thread of " << top_thread_message_id_
<< " in " << dialog_id_ << " by " << filter_; << " and in " << saved_messages_topic_id_ << " in " << dialog_id_ << " by " << filter_;
return promise_.set_error(Status::Error(400, "Message position is unknown")); return promise_.set_error(Status::Error(400, "Message position is unknown"));
} }
return promise_.set_value(std::move(messages->offset_id_offset_)); return promise_.set_value(std::move(messages->offset_id_offset_));
@ -21233,7 +21247,9 @@ void MessagesManager::get_dialog_message_count_from_server(DialogId dialog_id, M
} }
void MessagesManager::get_dialog_message_position(MessageFullId message_full_id, MessageSearchFilter filter, void MessagesManager::get_dialog_message_position(MessageFullId message_full_id, MessageSearchFilter filter,
MessageId top_thread_message_id, Promise<int32> &&promise) { MessageId top_thread_message_id,
SavedMessagesTopicId saved_messages_topic_id,
Promise<int32> &&promise) {
auto dialog_id = message_full_id.get_dialog_id(); auto dialog_id = message_full_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id, "get_dialog_message_position"); Dialog *d = get_dialog_force(dialog_id, "get_dialog_message_position");
if (d == nullptr) { if (d == nullptr) {
@ -21266,6 +21282,14 @@ void MessagesManager::get_dialog_message_position(MessageFullId message_full_id,
return promise.set_error(Status::Error(400, "Message doesn't belong to the message thread")); return promise.set_error(Status::Error(400, "Message doesn't belong to the message thread"));
} }
} }
if (saved_messages_topic_id != SavedMessagesTopicId()) {
if (dialog_id != td_->dialog_manager_->get_my_dialog_id()) {
return promise.set_error(Status::Error(400, "Can't filter by Saved Messages topic in the chat"));
}
if (!saved_messages_topic_id.have_input_peer(td_)) {
return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified"));
}
}
if (dialog_id.get_type() == DialogType::SecretChat) { if (dialog_id.get_type() == DialogType::SecretChat) {
return promise.set_error(Status::Error(400, "The method can't be used in secret chats")); return promise.set_error(Status::Error(400, "The method can't be used in secret chats"));
} }
@ -21276,7 +21300,7 @@ void MessagesManager::get_dialog_message_position(MessageFullId message_full_id,
} }
td_->create_handler<GetMessagePositionQuery>(std::move(promise)) td_->create_handler<GetMessagePositionQuery>(std::move(promise))
->send(dialog_id, message_id, filter, top_thread_message_id); ->send(dialog_id, message_id, filter, top_thread_message_id, saved_messages_topic_id);
} }
void MessagesManager::preload_newer_messages(const Dialog *d, MessageId max_message_id) { void MessagesManager::preload_newer_messages(const Dialog *d, MessageId max_message_id) {

View File

@ -747,7 +747,8 @@ class MessagesManager final : public Actor {
Promise<int32> &&promise); Promise<int32> &&promise);
void get_dialog_message_position(MessageFullId message_full_id, MessageSearchFilter filter, void get_dialog_message_position(MessageFullId message_full_id, MessageSearchFilter filter,
MessageId top_thread_message_id, Promise<int32> &&promise); MessageId top_thread_message_id, SavedMessagesTopicId saved_messages_topic_id,
Promise<int32> &&promise);
vector<MessageId> get_dialog_scheduled_messages(DialogId dialog_id, bool force, bool ignore_result, vector<MessageId> get_dialog_scheduled_messages(DialogId dialog_id, bool force, bool ignore_result,
Promise<Unit> &&promise); Promise<Unit> &&promise);

View File

@ -72,9 +72,12 @@ td_api::object_ptr<td_api::SavedMessagesTopic> SavedMessagesTopicId::get_saved_m
td->messages_manager_->get_chat_id_object(dialog_id_, "savedMessagesTopicSavedFromChat")); td->messages_manager_->get_chat_id_object(dialog_id_, "savedMessagesTopicSavedFromChat"));
} }
bool SavedMessagesTopicId::have_input_peer(const Td *td) const { bool SavedMessagesTopicId::have_input_peer(Td *td) const {
return dialog_id_.get_type() != DialogType::SecretChat && if (dialog_id_.get_type() == DialogType::SecretChat ||
td->dialog_manager_->have_input_peer(dialog_id_, AccessRights::Know); !td->dialog_manager_->have_dialog_info_force(dialog_id_, "SavedMessagesTopicId::have_input_peer")) {
return false;
}
return td->dialog_manager_->have_input_peer(dialog_id_, AccessRights::Know);
} }
telegram_api::object_ptr<telegram_api::InputPeer> SavedMessagesTopicId::get_input_peer(const Td *td) const { telegram_api::object_ptr<telegram_api::InputPeer> SavedMessagesTopicId::get_input_peer(const Td *td) const {

View File

@ -44,7 +44,7 @@ class SavedMessagesTopicId {
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic_object(Td *td) const; td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic_object(Td *td) const;
bool have_input_peer(const Td *td) const; bool have_input_peer(Td *td) const;
telegram_api::object_ptr<telegram_api::InputPeer> get_input_peer(const Td *td) const; telegram_api::object_ptr<telegram_api::InputPeer> get_input_peer(const Td *td) const;

View File

@ -5307,9 +5307,10 @@ void Td::on_request(uint64 id, const td_api::getChatMessagePosition &request) {
promise.set_value(make_tl_object<td_api::count>(result.move_as_ok())); promise.set_value(make_tl_object<td_api::count>(result.move_as_ok()));
} }
}); });
messages_manager_->get_dialog_message_position({DialogId(request.chat_id_), MessageId(request.message_id_)}, messages_manager_->get_dialog_message_position(
get_message_search_filter(request.filter_), {DialogId(request.chat_id_), MessageId(request.message_id_)}, get_message_search_filter(request.filter_),
MessageId(request.message_thread_id_), std::move(query_promise)); MessageId(request.message_thread_id_), SavedMessagesTopicId(this, request.saved_messages_topic_),
std::move(query_promise));
} }
void Td::on_request(uint64 id, const td_api::getChatScheduledMessages &request) { void Td::on_request(uint64 id, const td_api::getChatScheduledMessages &request) {

View File

@ -947,8 +947,17 @@ class CliClient final : public Actor {
} }
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic() const { td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic() const {
if (saved_messages_topic_ == 0) {
return nullptr; return nullptr;
} }
if (saved_messages_topic_ == my_id_) {
return td_api::make_object<td_api::savedMessagesTopicMyNotes>();
}
if (saved_messages_topic_ == -1) {
return td_api::make_object<td_api::savedMessagesTopicAuthorHidden>();
}
return td_api::make_object<td_api::savedMessagesTopicSavedFromChat>(saved_messages_topic_);
}
td_api::object_ptr<td_api::linkPreviewOptions> get_link_preview_options() const { td_api::object_ptr<td_api::linkPreviewOptions> get_link_preview_options() const {
if (!link_preview_is_disabled_ && link_preview_url_.empty() && !link_preview_force_small_media_ && if (!link_preview_is_disabled_ && link_preview_url_.empty() && !link_preview_force_small_media_ &&
@ -2953,7 +2962,7 @@ class CliClient final : public Actor {
string filter; string filter;
get_args(args, chat_id, message_id, filter); get_args(args, chat_id, message_id, filter);
send_request(td_api::make_object<td_api::getChatMessagePosition>( send_request(td_api::make_object<td_api::getChatMessagePosition>(
chat_id, message_id, as_search_messages_filter(filter), message_thread_id_)); chat_id, message_id, as_search_messages_filter(filter), message_thread_id_, get_saved_messages_topic()));
} else if (op == "gup" || op == "gupp") { } else if (op == "gup" || op == "gupp") {
UserId user_id; UserId user_id;
int32 offset; int32 offset;
@ -4596,6 +4605,8 @@ class CliClient final : public Actor {
} else if (op == "slpo") { } else if (op == "slpo") {
get_args(args, link_preview_is_disabled_, link_preview_url_, link_preview_force_small_media_, get_args(args, link_preview_is_disabled_, link_preview_url_, link_preview_force_small_media_,
link_preview_force_large_media_, link_preview_show_above_text_); link_preview_force_large_media_, link_preview_show_above_text_);
} else if (op == "ssmt") {
saved_messages_topic_ = as_chat_id(args);
} else if (op == "sm" || op == "sms" || op == "smf") { } else if (op == "sm" || op == "sms" || op == "smf") {
ChatId chat_id; ChatId chat_id;
string message; string message;
@ -6443,6 +6454,7 @@ class CliClient final : public Actor {
bool link_preview_force_small_media_ = false; bool link_preview_force_small_media_ = false;
bool link_preview_force_large_media_ = false; bool link_preview_force_large_media_ = false;
bool link_preview_show_above_text_ = false; bool link_preview_show_above_text_ = false;
int64 saved_messages_topic_ = 0;
ConcurrentScheduler *scheduler_{nullptr}; ConcurrentScheduler *scheduler_{nullptr};