Return multiple payment options in premiumState.

This commit is contained in:
levlam 2022-08-25 22:51:04 +03:00
parent 60c7a8a622
commit 2e31ba5188
6 changed files with 32 additions and 15 deletions

View File

@ -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<premiumGiftOption> 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<premiumPaymentOption> 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<int53> = 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<premiumFeaturePromotionAnimation> = PremiumState;
premiumState state:formattedText payment_options:vector<premiumPaymentOption> animations:vector<premiumFeaturePromotionAnimation> = PremiumState;
//@class StorePaymentPurpose @description Describes a purpose of an in-store payment

View File

@ -16855,7 +16855,7 @@ tl_object_ptr<td_api::userFullInfo> 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<td_api::userFullInfo>(

View File

@ -24390,7 +24390,6 @@ vector<AvailableReaction> MessagesManager::get_message_available_reactions(const
vector<AvailableReaction> 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<int64>(m->reactions->reactions_.size()) < reactions_uniq_max;

View File

@ -156,8 +156,14 @@ class GetPremiumPromoQuery final : public Td::ResultHandler {
std::move(animation_object)));
}
promise_.set_value(td_api::make_object<td_api::premiumState>(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<td_api::premiumState>(get_formatted_text_object(state, true, 0),
std::move(payment_options), std::move(animations)));
}
void on_error(Status status) final {

View File

@ -28,11 +28,23 @@ PremiumGiftOption::PremiumGiftOption(telegram_api::object_ptr<telegram_api::prem
}
}
PremiumGiftOption::PremiumGiftOption(telegram_api::object_ptr<telegram_api::premiumSubscriptionOption> &&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<int64>(1) << 40;
}
}
double PremiumGiftOption::get_monthly_price() const {
return static_cast<double>(amount_) / static_cast<double>(months_);
}
td_api::object_ptr<td_api::premiumGiftOption> PremiumGiftOption::get_premium_gift_option_object(
td_api::object_ptr<td_api::premiumPaymentOption> 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<td_api::premiumGiftOption> PremiumGiftOption::get_premium_gif
discount_percentage = static_cast<int32>(100 * (1.0 - relative_price));
}
}
return td_api::make_object<td_api::premiumGiftOption>(
return td_api::make_object<td_api::premiumPaymentOption>(
currency_, amount_, discount_percentage, months_, store_product_,
link_type == nullptr ? nullptr : link_type->get_internal_link_type_object());
}

View File

@ -29,8 +29,9 @@ class PremiumGiftOption {
public:
PremiumGiftOption() = default;
explicit PremiumGiftOption(telegram_api::object_ptr<telegram_api::premiumGiftOption> &&option);
explicit PremiumGiftOption(telegram_api::object_ptr<telegram_api::premiumSubscriptionOption> &&option);
td_api::object_ptr<td_api::premiumGiftOption> get_premium_gift_option_object(
td_api::object_ptr<td_api::premiumPaymentOption> get_premium_payment_option_object(
const PremiumGiftOption &base_option) const;
template <class StorerT>