Rebase: Support quote in ReplyParameters.

This commit is contained in:
David Guillen Fandos 2024-02-03 11:43:50 +01:00
parent 19a7da41b2
commit 94bfd307f8
2 changed files with 47 additions and 36 deletions

View File

@ -5842,13 +5842,17 @@ void Client::check_message(td::Slice chat_id_str, int64 message_id, bool allow_e
template <class OnSuccess>
void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters,
int64 message_thread_id, PromisedQueryPtr query, OnSuccess on_success) {
check_message(chat_id_str, reply_parameters.reply_to_message_id,
reply_parameters.reply_to_message_id <= 0 || reply_parameters.allow_sending_without_reply,
AccessRights::Write, "message to reply", std::move(query),
[this, message_thread_id, on_success = std::move(on_success)](int64 chat_id, int64 reply_to_message_id,
PromisedQueryPtr query) mutable {
check_message(
chat_id_str, reply_parameters.reply_to_message_id,
reply_parameters.reply_to_message_id <= 0 || reply_parameters.allow_sending_without_reply, AccessRights::Write,
"message to reply", std::move(query),
[this, message_thread_id, quote = std::move(reply_parameters.quote), on_success = std::move(on_success)](
int64 chat_id, int64 reply_to_message_id, PromisedQueryPtr query) mutable {
CheckedReplyParameters reply_parameters;
reply_parameters.reply_to_message_id = reply_to_message_id;
if (reply_to_message_id > 0) {
reply_parameters.quote = std::move(quote);
}
if (message_thread_id <= 0) {
return on_success(chat_id, 0, std::move(reply_parameters), std::move(query));
@ -6687,9 +6691,10 @@ bool Client::to_bool(td::MutableSlice value) {
}
td_api::object_ptr<td_api::InputMessageReplyTo> Client::get_input_message_reply_to(
const CheckedReplyParameters &reply_parameters) {
CheckedReplyParameters &&reply_parameters) {
if (reply_parameters.reply_to_message_id > 0) {
return make_object<td_api::inputMessageReplyToMessage>(0, reply_parameters.reply_to_message_id, nullptr);
return make_object<td_api::inputMessageReplyToMessage>(0, reply_parameters.reply_to_message_id,
std::move(reply_parameters.quote));
}
return nullptr;
}
@ -6724,10 +6729,15 @@ td::Result<Client::InputReplyParameters> Client::get_reply_parameters(td::JsonVa
auto &object = value.get_object();
TRY_RESULT(message_id, object.get_required_int_field("message_id"));
TRY_RESULT(allow_sending_without_reply, object.get_optional_bool_field("allow_sending_without_reply"));
TRY_RESULT(input_quote, object.get_optional_string_field("quote"));
TRY_RESULT(parse_mode, object.get_optional_string_field("quote_parse_mode"));
TRY_RESULT(quote,
get_formatted_text(std::move(input_quote), std::move(parse_mode), object.extract_field("quote_entities")));
InputReplyParameters result;
result.reply_to_message_id = as_tdlib_message_id(td::max(message_id, 0));
result.allow_sending_without_reply = allow_sending_without_reply;
result.quote = std::move(quote);
return std::move(result);
}
@ -9756,7 +9766,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
send_request(
make_object<td_api::sendMessageAlbum>(
chat_id, message_thread_id, get_input_message_reply_to(reply_parameters),
chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)),
get_message_send_options(disable_notification, protect_content), std::move(send_at), std::move(input_message_contents)),
td::make_unique<TdOnSendMessageAlbumCallback>(this, chat_id, message_count, std::move(query)));
};
@ -12010,8 +12020,8 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
}
count++;
send_request(
make_object<td_api::sendMessage>(chat_id, message_thread_id, get_input_message_reply_to(reply_parameters),
send_request(make_object<td_api::sendMessage>(chat_id, message_thread_id,
get_input_message_reply_to(std::move(reply_parameters)),
get_message_send_options(disable_notification, protect_content), std::move(send_at),
std::move(reply_markup), std::move(input_message_content)),
td::make_unique<TdOnSendMessageCallback>(this, chat_id, std::move(query)));

View File

@ -287,10 +287,12 @@ class Client final : public WebhookActor::Callback {
struct InputReplyParameters {
int64 reply_to_message_id = 0;
bool allow_sending_without_reply = false;
object_ptr<td_api::formattedText> quote;
};
struct CheckedReplyParameters {
int64 reply_to_message_id = 0;
object_ptr<td_api::formattedText> quote;
};
struct UserInfo;
@ -395,8 +397,7 @@ class Client final : public WebhookActor::Callback {
static bool to_bool(td::MutableSlice value);
static object_ptr<td_api::InputMessageReplyTo> get_input_message_reply_to(
const CheckedReplyParameters &reply_parameters);
static object_ptr<td_api::InputMessageReplyTo> get_input_message_reply_to(CheckedReplyParameters &&reply_parameters);
static td::Result<InputReplyParameters> get_reply_parameters(const Query *query);