Add td_api::inputMessageReplyToExternalMessage.

This commit is contained in:
levlam 2024-06-13 18:01:46 +03:00
parent 8ca99fb186
commit b33c7d9a02
5 changed files with 52 additions and 36 deletions

View File

@ -1520,11 +1520,16 @@ messageReplyToStory story_sender_chat_id:int53 story_id:int32 = MessageReplyTo;
//@class InputMessageReplyTo @description Contains information about the message or the story to be replied
//@description Describes a message to be replied
//@chat_id The identifier of the chat to which the message to be replied belongs; pass 0 if the message to be replied is in the same chat. Must always be 0 for replies in secret chats. A message can be replied in another chat or topic only if message.can_be_replied_in_another_chat
//@message_id The identifier of the message to be replied in the same or the specified chat
//@description Describes a message to be replied in the same chat and forum topic
//@message_id The identifier of the message to be replied in the same chat and forum topic
//@quote Quote from the message to be replied; pass null if none. Must always be null for replies in secret chats
inputMessageReplyToMessage chat_id:int53 message_id:int53 quote:inputTextQuote = InputMessageReplyTo;
inputMessageReplyToMessage message_id:int53 quote:inputTextQuote = InputMessageReplyTo;
//@description Describes a message to be replied that is from a different chat or a forum topic; not supported in secret chats
//@chat_id The identifier of the chat to which the message to be replied belongs
//@message_id The identifier of the message to be replied in the specified chat. A message can be replied in another chat or topic only if message.can_be_replied_in_another_chat
//@quote Quote from the message to be replied; pass null if none
inputMessageReplyToExternalMessage chat_id:int53 message_id:int53 quote:inputTextQuote = InputMessageReplyTo;
//@description Describes a story to be replied
//@story_sender_chat_id The identifier of the sender of the story. Currently, stories can be replied only in the sender's chat and channel stories can't be replied

View File

@ -763,11 +763,10 @@ MessageInputReplyTo BusinessConnectionManager::create_business_message_input_rep
if (!message_id.is_valid() || !message_id.is_server()) {
return {};
}
if (reply_to_message->chat_id_ != 0) {
return {};
}
return MessageInputReplyTo{message_id, DialogId(), MessageQuote(td_, std::move(reply_to_message->quote_))};
}
case td_api::inputMessageReplyToExternalMessage::ID:
return {};
default:
UNREACHABLE();
return {};

View File

@ -120,9 +120,13 @@ td_api::object_ptr<td_api::InputMessageReplyTo> MessageInputReplyTo::get_input_m
if (!message_id_.is_valid() && !message_id_.is_valid_scheduled()) {
return nullptr;
}
return td_api::make_object<td_api::inputMessageReplyToMessage>(
td->dialog_manager_->get_chat_id_object(dialog_id_, "inputMessageReplyToMessage"), message_id_.get(),
quote_.get_input_text_quote_object());
if (dialog_id_ != DialogId()) {
return td_api::make_object<td_api::inputMessageReplyToExternalMessage>(
td->dialog_manager_->get_chat_id_object(dialog_id_, "inputMessageReplyToExternalMessage"), message_id_.get(),
quote_.get_input_text_quote_object());
}
return td_api::make_object<td_api::inputMessageReplyToMessage>(message_id_.get(),
quote_.get_input_text_quote_object());
}
MessageId MessageInputReplyTo::get_same_chat_reply_to_message_id() const {

View File

@ -23218,43 +23218,48 @@ MessageInputReplyTo MessagesManager::create_message_input_reply_to(
}
return {};
}
auto *reply_d = d;
auto reply_dialog_id = DialogId(reply_to_message->chat_id_);
if (reply_dialog_id != DialogId()) {
reply_d = get_dialog_force(reply_dialog_id, "create_message_input_reply_to");
if (reply_d == nullptr) {
return {};
}
if (d->dialog_id.get_type() == DialogType::SecretChat) {
return {};
}
}
message_id = get_persistent_message_id(reply_d, message_id);
if (message_id == MessageId(ServerMessageId(1)) && reply_d->dialog_id.get_type() == DialogType::Channel) {
message_id = get_persistent_message_id(d, message_id);
if (message_id == MessageId(ServerMessageId(1)) && d->dialog_id.get_type() == DialogType::Channel) {
return {};
}
const Message *m = get_message_force(reply_d, message_id, "create_message_input_reply_to 2");
const Message *m = get_message_force(d, message_id, "create_message_input_reply_to 2");
if (m == nullptr || m->message_id.is_yet_unsent() ||
(m->message_id.is_local() && reply_d->dialog_id.get_type() != DialogType::SecretChat)) {
if (message_id.is_server() && reply_d->dialog_id.get_type() != DialogType::SecretChat &&
reply_dialog_id == DialogId() && message_id > reply_d->last_new_message_id &&
(reply_d->notification_info != nullptr &&
message_id <= reply_d->notification_info->max_push_notification_message_id_)) {
(m->message_id.is_local() && d->dialog_id.get_type() != DialogType::SecretChat)) {
if (message_id.is_server() && d->dialog_id.get_type() != DialogType::SecretChat &&
message_id > d->last_new_message_id &&
(d->notification_info != nullptr &&
message_id <= d->notification_info->max_push_notification_message_id_)) {
// allow to reply yet unreceived server message in the same chat
return MessageInputReplyTo{message_id, reply_dialog_id,
MessageQuote{td_, std::move(reply_to_message->quote_)}};
return MessageInputReplyTo{message_id, DialogId(), MessageQuote{td_, std::move(reply_to_message->quote_)}};
}
if (!for_draft && top_thread_message_id.is_valid() && top_thread_message_id.is_server()) {
return MessageInputReplyTo{top_thread_message_id, DialogId(), MessageQuote()};
}
LOG(INFO) << "Can't find " << message_id << " in " << reply_d->dialog_id;
LOG(INFO) << "Can't find " << message_id << " in " << d->dialog_id;
// TODO local replies to local messages can be allowed
// TODO replies to yet unsent messages can be allowed with special handling of them on application restart
return {};
}
if (reply_dialog_id != DialogId() && (!can_forward_message(reply_dialog_id, m) || !m->message_id.is_server())) {
LOG(INFO) << "Can't reply in another chat " << m->message_id << " in " << reply_d->dialog_id;
return MessageInputReplyTo{m->message_id, DialogId(), MessageQuote{td_, std::move(reply_to_message->quote_)}};
}
case td_api::inputMessageReplyToExternalMessage::ID: {
auto reply_to_message = td_api::move_object_as<td_api::inputMessageReplyToExternalMessage>(reply_to);
if (d->dialog_id.get_type() == DialogType::SecretChat) {
return {};
}
auto reply_dialog_id = DialogId(reply_to_message->chat_id_);
auto *reply_d = get_dialog_force(reply_dialog_id, "create_message_input_reply_to");
if (reply_d == nullptr) {
return {};
}
auto message_id = get_persistent_message_id(reply_d, MessageId(reply_to_message->message_id_));
if (message_id == MessageId(ServerMessageId(1)) && reply_d->dialog_id.get_type() == DialogType::Channel) {
return {};
}
const Message *m = get_message_force(reply_d, message_id, "create_message_input_reply_to 2");
if (!can_forward_message(reply_dialog_id, m) || !m->message_id.is_valid() || !m->message_id.is_server()) {
LOG(INFO) << "Can't reply in another chat " << message_id << " in " << reply_d->dialog_id;
return {};
}
return MessageInputReplyTo{m->message_id, reply_dialog_id,

View File

@ -955,8 +955,11 @@ class CliClient final : public Actor {
if (!reply_quote_.empty()) {
quote = td_api::make_object<td_api::inputTextQuote>(as_formatted_text(reply_quote_), reply_quote_position_);
}
return td_api::make_object<td_api::inputMessageReplyToMessage>(reply_chat_id_, reply_message_id_,
std::move(quote));
if (reply_chat_id_ == 0) {
return td_api::make_object<td_api::inputMessageReplyToMessage>(reply_message_id_, std::move(quote));
}
return td_api::make_object<td_api::inputMessageReplyToExternalMessage>(reply_chat_id_, reply_message_id_,
std::move(quote));
}
if (reply_story_chat_id_ != 0 || reply_story_id_ != 0) {
return td_api::make_object<td_api::inputMessageReplyToStory>(reply_story_chat_id_, reply_story_id_);