From 8c358a4fc56a41b2cf1bc183946d1762c888b17c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 18 Jan 2024 17:38:15 +0300 Subject: [PATCH] Add SavedMessagesTopicId::is_valid_status. --- td/telegram/MessagesManager.cpp | 26 ++++++-------------------- td/telegram/SavedMessagesTopicId.cpp | 10 ++++++++++ td/telegram/SavedMessagesTopicId.h | 2 ++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 0223d3770..c5bfa1cff 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -16227,11 +16227,7 @@ void MessagesManager::get_saved_messages_topic_history(SavedMessagesTopicId save return promise.set_error(Status::Error(400, "Parameter offset must be greater than or equal to -limit")); } - if (!saved_messages_topic_id.is_valid()) { - return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified")); - } - auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); - TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id)); + TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_status(td_)); if (from_message_id == MessageId() || from_message_id.get() > MessageId::max().get()) { from_message_id = MessageId::max(); @@ -16246,25 +16242,18 @@ void MessagesManager::get_saved_messages_topic_history(SavedMessagesTopicId save void MessagesManager::delete_saved_messages_topic_history(SavedMessagesTopicId saved_messages_topic_id, Promise &&promise) { - if (!saved_messages_topic_id.is_valid()) { - return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified")); - } - auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); - TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id)); + TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_status(td_)); AffectedHistoryQuery query = [td = td_, saved_messages_topic_id](DialogId, Promise &&query_promise) { td->create_handler(std::move(query_promise))->send(saved_messages_topic_id); }; + auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); run_affected_history_query_until_complete(my_dialog_id, std::move(query), true, std::move(promise)); } void MessagesManager::get_saved_messages_topic_message_by_date(SavedMessagesTopicId saved_messages_topic_id, int32 date, Promise> &&promise) { - if (!saved_messages_topic_id.is_valid()) { - return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified")); - } - auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); - TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id)); + TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_status(td_)); if (date <= 0) { date = 1; @@ -16276,11 +16265,7 @@ void MessagesManager::get_saved_messages_topic_message_by_date(SavedMessagesTopi void MessagesManager::delete_saved_messages_topic_messages_by_date(SavedMessagesTopicId saved_messages_topic_id, int32 min_date, int32 max_date, Promise &&promise) { - if (!saved_messages_topic_id.is_valid()) { - return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified")); - } - auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); - TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id)); + TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_status(td_)); if (min_date > max_date) { return promise.set_error(Status::Error(400, "Wrong date interval specified")); @@ -16308,6 +16293,7 @@ void MessagesManager::delete_saved_messages_topic_messages_by_date(SavedMessages td->create_handler(std::move(query_promise)) ->send(saved_messages_topic_id, min_date, max_date); }; + auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id(); run_affected_history_query_until_complete(my_dialog_id, std::move(query), true, std::move(promise)); } diff --git a/td/telegram/SavedMessagesTopicId.cpp b/td/telegram/SavedMessagesTopicId.cpp index c9debb190..d250650f3 100644 --- a/td/telegram/SavedMessagesTopicId.cpp +++ b/td/telegram/SavedMessagesTopicId.cpp @@ -80,6 +80,16 @@ bool SavedMessagesTopicId::have_input_peer(Td *td) const { return td->dialog_manager_->have_input_peer(dialog_id_, AccessRights::Know); } +Status SavedMessagesTopicId::is_valid_status(Td *td) const { + if (!dialog_id_.is_valid()) { + return Status::Error(400, "Invalid Saved Messages topic specified"); + } + if (!have_input_peer(td)) { + return Status::Error(400, "Invalid Saved Messages topic specified"); + } + return Status::OK(); +} + Status SavedMessagesTopicId::is_valid_in(Td *td, DialogId dialog_id) const { if (dialog_id_ != DialogId()) { if (dialog_id != td->dialog_manager_->get_my_dialog_id()) { diff --git a/td/telegram/SavedMessagesTopicId.h b/td/telegram/SavedMessagesTopicId.h index 049fa8c62..f20481e73 100644 --- a/td/telegram/SavedMessagesTopicId.h +++ b/td/telegram/SavedMessagesTopicId.h @@ -45,6 +45,8 @@ class SavedMessagesTopicId { return dialog_id_.is_valid(); } + Status is_valid_status(Td *td) const; + Status is_valid_in(Td *td, DialogId dialog_id) const; td_api::object_ptr get_saved_messages_topic_object(Td *td) const;