Allow to change reply quote in resendMessages.

This commit is contained in:
levlam 2023-11-06 13:20:16 +03:00
parent 0139e73910
commit 8228c2e7b6
7 changed files with 34 additions and 9 deletions

View File

@ -7063,7 +7063,8 @@ forwardMessages chat_id:int53 message_thread_id:int53 from_chat_id:int53 message
//-If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message
//@chat_id Identifier of the chat to send messages
//@message_ids Identifiers of the messages to resend. Message identifiers must be in a strictly increasing order
resendMessages chat_id:int53 message_ids:vector<int53> = Messages;
//@quote New manually chosen quote from the message to reply; pass null if none. Ignored if more than one message is re-sent, or if messageSendingStateFailed.need_another_reply_quote == false
resendMessages chat_id:int53 message_ids:vector<int53> quote:formattedText = Messages;
//@description Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message
//@chat_id Target chat

View File

@ -62,6 +62,14 @@ class MessageInputReplyTo {
return !is_empty();
}
bool has_quote() const {
return !quote_.text.empty();
}
void set_quote(FormattedText &&quote) {
quote_ = std::move(quote);
}
StoryFullId get_story_full_id() const {
return story_full_id_;
}

View File

@ -28272,7 +28272,8 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
return get_messages_object(-1, std::move(result), false);
}
Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, vector<MessageId> message_ids) {
Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, vector<MessageId> message_ids,
td_api::object_ptr<td_api::formattedText> &&quote) {
if (message_ids.empty()) {
return Status::Error(400, "There are no messages to resend");
}
@ -28361,6 +28362,17 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
auto need_another_sender =
message->send_error_code == 400 && message->send_error_message == CSlice("SEND_AS_PEER_INVALID");
auto need_another_reply_quote =
message->send_error_code == 400 && message->send_error_message == CSlice("QUOTE_TEXT_INVALID");
if (need_another_reply_quote && message_ids.size() == 1 && quote != nullptr) {
CHECK(message->input_reply_to.is_valid());
CHECK(message->input_reply_to.has_quote()); // checked in on_send_message_fail
auto r_quote =
get_formatted_text(td_, get_my_dialog_id(), std::move(quote), td_->auth_manager_->is_bot(), true, true, true);
if (r_quote.is_ok()) {
message->input_reply_to.set_quote(r_quote.move_as_ok());
}
}
MessageSendOptions options(message->disable_notification, message->from_background,
message->update_stickersets_order, message->noforwards, false,
get_message_schedule_date(message.get()), message->sending_id);
@ -31211,7 +31223,7 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) {
}
if (error.message() == "QUOTE_TEXT_INVALID") {
auto *input_reply_to = get_message_input_reply_to(m);
if (input_reply_to != nullptr && !input_reply_to->is_empty()) {
if (input_reply_to != nullptr && !input_reply_to->is_empty() && input_reply_to->has_quote()) {
auto reply_message_full_id = input_reply_to->get_reply_message_full_id(dialog_id);
if (reply_message_full_id.get_message_id().is_valid()) {
get_message_from_server(reply_message_full_id, Auto(), "QUOTE_TEXT_INVALID");

View File

@ -465,7 +465,8 @@ class MessagesManager final : public Actor {
tl_object_ptr<td_api::messageSendOptions> &&options, bool in_game_share,
vector<MessageCopyOptions> &&copy_options) TD_WARN_UNUSED_RESULT;
Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids) TD_WARN_UNUSED_RESULT;
Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids,
td_api::object_ptr<td_api::formattedText> &&quote) TD_WARN_UNUSED_RESULT;
void set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise);

View File

@ -5911,9 +5911,10 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) {
}
}
void Td::on_request(uint64 id, const td_api::resendMessages &request) {
void Td::on_request(uint64 id, td_api::resendMessages &request) {
DialogId dialog_id(request.chat_id_);
auto r_message_ids = messages_manager_->resend_messages(dialog_id, MessageId::get_message_ids(request.message_ids_));
auto r_message_ids = messages_manager_->resend_messages(dialog_id, MessageId::get_message_ids(request.message_ids_),
std::move(request.quote_));
if (r_message_ids.is_error()) {
return send_closure(actor_id(this), &Td::send_error, id, r_message_ids.move_as_error());
}

View File

@ -856,7 +856,7 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::forwardMessages &request);
void on_request(uint64 id, const td_api::resendMessages &request);
void on_request(uint64 id, td_api::resendMessages &request);
void on_request(uint64 id, td_api::getWebPagePreview &request);

View File

@ -3715,8 +3715,10 @@ class CliClient final : public Actor {
} else if (op == "resend") {
ChatId chat_id;
string message_ids;
get_args(args, chat_id, message_ids);
send_request(td_api::make_object<td_api::resendMessages>(chat_id, as_message_ids(message_ids)));
string quote;
get_args(args, chat_id, message_ids, quote);
send_request(
td_api::make_object<td_api::resendMessages>(chat_id, as_message_ids(message_ids), as_formatted_text(quote)));
} else if (op == "csc" || op == "CreateSecretChat") {
send_request(td_api::make_object<td_api::createSecretChat>(as_secret_chat_id(args)));
} else if (op == "cnsc" || op == "CreateNewSecretChat") {