From 94bfd307f85b58952cfd0fe07b450e4dc1a10fab Mon Sep 17 00:00:00 2001 From: David Guillen Fandos Date: Sat, 3 Feb 2024 11:43:50 +0100 Subject: [PATCH] Rebase: Support quote in ReplyParameters. --- telegram-bot-api/Client.cpp | 78 +++++++++++++++++++++---------------- telegram-bot-api/Client.h | 5 ++- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index f9a0ca6..d081a12 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -5842,35 +5842,39 @@ void Client::check_message(td::Slice chat_id_str, int64 message_id, bool allow_e template 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 { - CheckedReplyParameters reply_parameters; - reply_parameters.reply_to_message_id = reply_to_message_id; + 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)); - } + if (message_thread_id <= 0) { + return on_success(chat_id, 0, std::move(reply_parameters), std::move(query)); + } - if (reply_to_message_id != 0) { - const MessageInfo *message_info = get_message(chat_id, reply_to_message_id, true); - CHECK(message_info != nullptr); - if (message_info->message_thread_id != message_thread_id) { - return fail_query_with_error(std::move(query), 400, "MESSAGE_THREAD_INVALID", - "Replied message is not in the specified message thread"); - } - } - if (reply_to_message_id == message_thread_id) { - return on_success(chat_id, message_thread_id, std::move(reply_parameters), std::move(query)); - } + if (reply_to_message_id != 0) { + const MessageInfo *message_info = get_message(chat_id, reply_to_message_id, true); + CHECK(message_info != nullptr); + if (message_info->message_thread_id != message_thread_id) { + return fail_query_with_error(std::move(query), 400, "MESSAGE_THREAD_INVALID", + "Replied message is not in the specified message thread"); + } + } + if (reply_to_message_id == message_thread_id) { + return on_success(chat_id, message_thread_id, std::move(reply_parameters), std::move(query)); + } - send_request(make_object(chat_id, message_thread_id), - td::make_unique>( - this, chat_id, message_thread_id, std::move(reply_parameters), std::move(query), - std::move(on_success))); - }); + send_request(make_object(chat_id, message_thread_id), + td::make_unique>( + this, chat_id, message_thread_id, std::move(reply_parameters), std::move(query), + std::move(on_success))); + }); } template @@ -6687,9 +6691,10 @@ bool Client::to_bool(td::MutableSlice value) { } td_api::object_ptr Client::get_input_message_reply_to( - const CheckedReplyParameters &reply_parameters) { + CheckedReplyParameters &&reply_parameters) { if (reply_parameters.reply_to_message_id > 0) { - return make_object(0, reply_parameters.reply_to_message_id, nullptr); + return make_object(0, reply_parameters.reply_to_message_id, + std::move(reply_parameters.quote)); } return nullptr; } @@ -6724,10 +6729,15 @@ td::Result 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( - 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(this, chat_id, message_count, std::move(query))); }; @@ -12010,11 +12020,11 @@ void Client::do_send_message(object_ptr input_messa } count++; - send_request( - make_object(chat_id, message_thread_id, get_input_message_reply_to(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(this, chat_id, std::move(query))); + send_request(make_object(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(this, chat_id, std::move(query))); }; check_reply_parameters(chat_id, std::move(reply_parameters), message_thread_id, std::move(query), std::move(on_success)); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 7542cce..e906481 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -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 quote; }; struct CheckedReplyParameters { int64 reply_to_message_id = 0; + object_ptr quote; }; struct UserInfo; @@ -395,8 +397,7 @@ class Client final : public WebhookActor::Callback { static bool to_bool(td::MutableSlice value); - static object_ptr get_input_message_reply_to( - const CheckedReplyParameters &reply_parameters); + static object_ptr get_input_message_reply_to(CheckedReplyParameters &&reply_parameters); static td::Result get_reply_parameters(const Query *query);