diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 23959e9a5..295327313 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -466,14 +466,14 @@ chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_pol chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messages:Bool can_edit_messages:Bool can_delete_messages:Bool can_invite_users:Bool can_restrict_members:Bool can_pin_messages:Bool can_promote_members:Bool can_manage_video_chats:Bool is_anonymous:Bool = ChatAdministratorRights; -//@description Describes an option for gifting Telegram Premium to a user +//@description Describes an option for buying Telegram Premium to a user //@currency ISO 4217 currency code for Telegram Premium subscription payment //@amount The amount to pay, in the smallest units of the currency -//@discount_percentage The discount associated with this gift option, as a percentage +//@discount_percentage The discount associated with this option, as a percentage //@month_count Number of month the Telegram Premium subscription will be active //@store_product_id Identifier of the store product associated with the option -//@payment_link An internal link to be opened for gifting Telegram Premium to the user if store payment isn't possible; may be null if direct payment isn't available -premiumGiftOption currency:string amount:int53 discount_percentage:int32 month_count:int32 store_product_id:string payment_link:InternalLinkType = PremiumGiftOption; +//@payment_link An internal link to be opened for buying Telegram Premium to the user if store payment isn't possible; may be null if direct payment isn't available +premiumPaymentOption currency:string amount:int53 discount_percentage:int32 month_count:int32 store_product_id:string payment_link:InternalLinkType = PremiumPaymentOption; //@description Represents a user @@ -524,7 +524,7 @@ botInfo share_text:string description:string photo:photo animation:animation men //@premium_gift_options The list of available options for gifting Telegram Premium to the user //@group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user //@bot_info For bots, information about the bot; may be null -userFullInfo photo:chatPhoto is_blocked:Bool can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool need_phone_number_privacy_exception:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 bot_info:botInfo = UserFullInfo; +userFullInfo photo:chatPhoto is_blocked:Bool can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool need_phone_number_privacy_exception:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; @@ -3056,10 +3056,9 @@ premiumFeaturePromotionAnimation feature:PremiumFeature animation:animation = Pr //@description Contains state of Telegram Premium subscription and promotion videos for Premium features //@state Text description of the state of the current Premium subscription; may be empty if the current user has no Telegram Premium subscription -//@currency ISO 4217 currency code for Telegram Premium subscription payment -//@monthly_amount Monthly subscription payment for Telegram Premium subscription, in the smallest units of the currency +//@payment_options The list of available options for buying Telegram Premium //@animations The list of available promotion animations for Premium features -premiumState state:formattedText currency:string monthly_amount:int53 animations:vector = PremiumState; +premiumState state:formattedText payment_options:vector animations:vector = PremiumState; //@class StorePaymentPurpose @description Describes a purpose of an in-store payment diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1e0e78af2..e73f0e6cf 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -16855,7 +16855,7 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U auto base_premium_gift_it = std::min_element(user_full->premium_gift_options.begin(), user_full->premium_gift_options.end()); auto premium_gift_options = transform(user_full->premium_gift_options, [&base_premium_gift_it](const auto &option) { - return option.get_premium_gift_option_object(*base_premium_gift_it); + return option.get_premium_payment_option_object(*base_premium_gift_it); }); auto voice_messages_forbidden = is_premium ? user_full->voice_messages_forbidden : false; return make_tl_object( diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e6ba03bba..1fcf5e409 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -24390,7 +24390,6 @@ vector MessagesManager::get_message_available_reactions(const vector result; if (can_use_reactions) { - bool is_premium = td_->option_manager_->get_option_boolean("is_premium"); int64 reactions_uniq_max = td_->option_manager_->get_option_integer("reactions_uniq_max", 11); bool can_add_new_reactions = m->reactions == nullptr || static_cast(m->reactions->reactions_.size()) < reactions_uniq_max; diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index c0fab14ca..238d3485b 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -156,8 +156,14 @@ class GetPremiumPromoQuery final : public Td::ResultHandler { std::move(animation_object))); } - promise_.set_value(td_api::make_object(get_formatted_text_object(state, true, 0), "USD", 499, - std::move(animations))); + auto period_options = transform(std::move(promo->period_options_), + [](auto &&period_option) { return PremiumGiftOption(std::move(period_option)); }); + auto base_premium_gift_it = std::min_element(period_options.begin(), period_options.end()); + auto payment_options = transform(period_options, [&base_premium_gift_it](const auto &option) { + return option.get_premium_payment_option_object(*base_premium_gift_it); + }); + promise_.set_value(td_api::make_object(get_formatted_text_object(state, true, 0), + std::move(payment_options), std::move(animations))); } void on_error(Status status) final { diff --git a/td/telegram/PremiumGiftOption.cpp b/td/telegram/PremiumGiftOption.cpp index 733ca57b9..f9be04091 100644 --- a/td/telegram/PremiumGiftOption.cpp +++ b/td/telegram/PremiumGiftOption.cpp @@ -28,11 +28,23 @@ PremiumGiftOption::PremiumGiftOption(telegram_api::object_ptr &&option) + : months_(option->months_) + , currency_(std::move(option->currency_)) + , amount_(option->amount_) + , bot_url_(std::move(option->bot_url_)) + , store_product_(std::move(option->store_product_)) { + if (amount_ <= 0 || !check_currency_amount(amount_)) { + LOG(ERROR) << "Receive invalid premium gift option amount " << amount_; + amount_ = static_cast(1) << 40; + } +} + double PremiumGiftOption::get_monthly_price() const { return static_cast(amount_) / static_cast(months_); } -td_api::object_ptr PremiumGiftOption::get_premium_gift_option_object( +td_api::object_ptr PremiumGiftOption::get_premium_payment_option_object( const PremiumGiftOption &base_option) const { auto link_type = LinkManager::parse_internal_link(bot_url_, true); int32 discount_percentage = 0; @@ -42,7 +54,7 @@ td_api::object_ptr PremiumGiftOption::get_premium_gif discount_percentage = static_cast(100 * (1.0 - relative_price)); } } - return td_api::make_object( + return td_api::make_object( currency_, amount_, discount_percentage, months_, store_product_, link_type == nullptr ? nullptr : link_type->get_internal_link_type_object()); } diff --git a/td/telegram/PremiumGiftOption.h b/td/telegram/PremiumGiftOption.h index cb235ee76..694fb24c8 100644 --- a/td/telegram/PremiumGiftOption.h +++ b/td/telegram/PremiumGiftOption.h @@ -29,8 +29,9 @@ class PremiumGiftOption { public: PremiumGiftOption() = default; explicit PremiumGiftOption(telegram_api::object_ptr &&option); + explicit PremiumGiftOption(telegram_api::object_ptr &&option); - td_api::object_ptr get_premium_gift_option_object( + td_api::object_ptr get_premium_payment_option_object( const PremiumGiftOption &base_option) const; template