Add SavedMessagesTopicId::is_valid_in.
This commit is contained in:
parent
3eba7d4f2b
commit
7e3107b1d3
@ -19988,13 +19988,10 @@ MessagesManager::FoundDialogMessages MessagesManager::search_dialog_messages(
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (saved_messages_topic_id != SavedMessagesTopicId()) {
|
||||
if (dialog_id != td_->dialog_manager_->get_my_dialog_id()) {
|
||||
promise.set_error(Status::Error(400, "Can't filter by Saved Messages topic in the chat"));
|
||||
return result;
|
||||
}
|
||||
if (!saved_messages_topic_id.have_input_peer(td_)) {
|
||||
promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified"));
|
||||
{
|
||||
auto status = saved_messages_topic_id.is_valid_in(td_, dialog_id);
|
||||
if (status.is_error()) {
|
||||
promise.set_error(std::move(status));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -21282,14 +21279,8 @@ 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"));
|
||||
}
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, dialog_id));
|
||||
|
||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||
return promise.set_error(Status::Error(400, "The method can't be used in secret chats"));
|
||||
}
|
||||
|
@ -80,6 +80,18 @@ bool SavedMessagesTopicId::have_input_peer(Td *td) const {
|
||||
return td->dialog_manager_->have_input_peer(dialog_id_, AccessRights::Know);
|
||||
}
|
||||
|
||||
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()) {
|
||||
return Status::Error(400, "Can't use Saved Messages topic in the chat");
|
||||
}
|
||||
if (!have_input_peer(td)) {
|
||||
return Status::Error(400, "Invalid Saved Messages topic specified");
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::InputPeer> SavedMessagesTopicId::get_input_peer(const Td *td) const {
|
||||
return td->dialog_manager_->get_input_peer(dialog_id_, AccessRights::Know);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/HashTableUtils.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
namespace td {
|
||||
@ -28,6 +29,8 @@ class SavedMessagesTopicId {
|
||||
|
||||
friend StringBuilder &operator<<(StringBuilder &string_builder, SavedMessagesTopicId saved_messages_topic_id);
|
||||
|
||||
bool have_input_peer(Td *td) const;
|
||||
|
||||
public:
|
||||
SavedMessagesTopicId() = default;
|
||||
|
||||
@ -42,9 +45,9 @@ class SavedMessagesTopicId {
|
||||
return dialog_id_.is_valid();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic_object(Td *td) const;
|
||||
Status is_valid_in(Td *td, DialogId dialog_id) const;
|
||||
|
||||
bool have_input_peer(Td *td) const;
|
||||
td_api::object_ptr<td_api::SavedMessagesTopic> get_saved_messages_topic_object(Td *td) const;
|
||||
|
||||
telegram_api::object_ptr<telegram_api::InputPeer> get_input_peer(const Td *td) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user