From f47e0a9fde27343dea9e1a80e87f898acaa803ff Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 30 Jun 2024 12:43:03 +0300 Subject: [PATCH] Update TDLib to 1.8.32. --- td | 2 +- telegram-bot-api/Client.cpp | 94 ++++++++++++++++++++++++++++++++----- telegram-bot-api/Client.h | 5 ++ 3 files changed, 89 insertions(+), 12 deletions(-) diff --git a/td b/td index 8f19c75..35cfcf5 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 8f19c751dc296cedb9a921badb7a02a8c0cb1aeb +Subproject commit 35cfcf5d15981b99e8f31a2195641f035dd516c3 diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 4ed5580..c26a74d 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -3177,6 +3177,8 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { object("boost_added", JsonChatBoostAdded(content)); break; } + case td_api::messagePaidMedia::ID: + break; default: UNREACHABLE(); } @@ -3974,10 +3976,10 @@ class Client::JsonStarTransactionPartner final : public td::Jsonable { } break; } - case td_api::starTransactionPartnerUser::ID: { - auto source_user = static_cast(source_); + case td_api::starTransactionPartnerBot::ID: { + auto source_user = static_cast(source_); object("type", "user"); - object("user", JsonUser(source_user->user_id_, client_)); + object("user", JsonUser(source_user->bot_user_id_, client_)); break; } case td_api::starTransactionPartnerTelegram::ID: @@ -3987,6 +3989,7 @@ class Client::JsonStarTransactionPartner final : public td::Jsonable { LOG(ERROR) << "Receive " << to_string(*source_); object("type", "other"); break; + case td_api::starTransactionPartnerTelegramAds::ID: case td_api::starTransactionPartnerUnsupported::ID: object("type", "other"); break; @@ -7915,7 +7918,7 @@ td::Result> Client::get_input_me need_email_address, need_shipping_address, send_phone_number_to_provider, send_email_address_to_provider, is_flexible), title, description, photo_url, photo_size, photo_width, photo_height, payload, provider_token, provider_data, - td::string(), nullptr); + td::string(), nullptr, nullptr); } if (is_input_message_content_required) { @@ -9318,10 +9321,10 @@ td::Result> Client::get_input_me td::vector(), duration, width, height, supports_streaming, std::move(caption), show_caption_above_media, nullptr, has_spoiler); } - if (for_album && type == "animation") { - return td::Status::Error(PSLICE() << "type \"" << type << "\" can't be used in sendMediaGroup"); - } if (type == "animation") { + if (for_album) { + return td::Status::Error(PSLICE() << "type \"" << type << "\" can't be used in sendMediaGroup"); + } TRY_RESULT(width, object.get_optional_int_field("width")); TRY_RESULT(height, object.get_optional_int_field("height")); TRY_RESULT(duration, object.get_optional_int_field("duration")); @@ -9399,6 +9402,67 @@ td::Result>> Client:: return std::move(contents); } +td::Result> Client::get_input_paid_media(const Query *query, + td::JsonValue &&input_media) const { + if (input_media.type() != td::JsonValue::Type::Object) { + return td::Status::Error("expected an Object"); + } + + auto &object = input_media.get_object(); + TRY_RESULT(media, object.get_optional_string_field("media")); + + auto input_file = get_input_file(query, td::Slice(), media, false); + if (input_file == nullptr) { + return td::Status::Error("media not found"); + } + + object_ptr input_thumbnail; + TRY_RESULT(thumbnail, object.get_optional_string_field("thumbnail")); + auto thumbnail_input_file = get_input_file(query, "thumbnail", thumbnail, true); + if (thumbnail_input_file != nullptr) { + input_thumbnail = make_object(std::move(thumbnail_input_file), 0, 0); + } + + TRY_RESULT(width, object.get_optional_int_field("width")); + TRY_RESULT(height, object.get_optional_int_field("height")); + width = td::clamp(width, 0, MAX_LENGTH); + height = td::clamp(height, 0, MAX_LENGTH); + + object_ptr media_type; + TRY_RESULT(type, object.get_required_string_field("type")); + if (type == "photo") { + media_type = make_object(); + } else if (type == "video") { + TRY_RESULT(duration, object.get_optional_int_field("duration")); + TRY_RESULT(supports_streaming, object.get_optional_bool_field("supports_streaming")); + duration = td::clamp(duration, 0, MAX_DURATION); + media_type = make_object(duration, supports_streaming); + } else { + return td::Status::Error(PSLICE() << "type \"" << type << "\" is unsupported"); + } + + return make_object(std::move(media_type), std::move(input_file), std::move(input_thumbnail), + td::vector(), width, height); +} + +td::Result> Client::get_input_paid_media(const Query *query, + td::Slice field_name) const { + TRY_RESULT(media, get_required_string_arg(query, field_name)); + + LOG(INFO) << "Parsing JSON object: " << media; + auto r_value = json_decode(media); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return td::Status::Error(400, "Can't parse input paid media JSON object"); + } + + auto r_input_paid_media = get_input_paid_media(query, r_value.move_as_ok()); + if (r_input_paid_media.is_error()) { + return td::Status::Error(400, PSLICE() << "Can't parse InputPaidMedia: " << r_input_paid_media.error().message()); + } + return r_input_paid_media.move_as_ok(); +} + td::Result> Client::get_input_message_invoice( const Query *query) const { TRY_RESULT(title, get_required_string_arg(query, "title")); @@ -9456,10 +9520,15 @@ td::Result> Client::get_input_me auto send_email_address_to_provider = to_bool(query->arg("send_email_to_provider")); auto is_flexible = to_bool(query->arg("is_flexible")); - object_ptr extended_media; - if (!query->arg("extended_media").empty()) { - TRY_RESULT_ASSIGN(extended_media, get_input_media(query, "extended_media")); + object_ptr paid_media; + if (!query->arg("paid_media").empty()) { + TRY_RESULT_ASSIGN(paid_media, get_input_paid_media(query, "paid_media")); + } else if (!query->arg("extended_media").empty()) { + TRY_RESULT_ASSIGN(paid_media, get_input_paid_media(query, "extended_media")); } + TRY_RESULT(paid_media_caption, get_formatted_text(query->arg("paid_media_caption").str(), + query->arg("paid_media_caption_parse_mode").str(), + get_input_entities(query, "paid_media_caption_entities"))); return make_object( make_object(currency.str(), std::move(prices), max_tip_amount, std::move(suggested_tip_amounts), @@ -9467,7 +9536,8 @@ td::Result> Client::get_input_me need_shipping_address, send_phone_number_to_provider, send_email_address_to_provider, is_flexible), title.str(), description.str(), photo_url.str(), photo_size, photo_width, photo_height, payload.str(), - provider_token.str(), provider_data.str(), start_parameter.str(), std::move(extended_media)); + provider_token.str(), provider_data.str(), start_parameter.str(), std::move(paid_media), + std::move(paid_media_caption)); } td::Result>> Client::get_poll_options(const Query *query) { @@ -13548,6 +13618,8 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr>> get_input_message_contents( const Query *query, td::JsonValue &&value) const; + td::Result> get_input_paid_media(const Query *query, + td::JsonValue &&input_media) const; + + td::Result> get_input_paid_media(const Query *query, td::Slice field_name) const; + td::Result> get_input_message_invoice(const Query *query) const; static object_ptr get_message_send_options(bool disable_notification,