Add information for Premium subscription upgrade.

This commit is contained in:
levlam 2023-01-20 00:41:18 +03:00
parent b339976ddf
commit 315a526fba
5 changed files with 55 additions and 5 deletions

View File

@ -620,6 +620,13 @@ chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messa
//@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 Describes an option for buying or upgrading Telegram Premium for self
//@payment_option Information about the payment option
//@is_current True, if this is the currently used Telegram Premium subscription option
//@is_upgrade True, if the payment option can be used to upgrade the existing Telegram Premium subscription
//@last_transaction_id Identifier of the last in-store transaction for the currently used option
premiumStatePaymentOption payment_option:premiumPaymentOption is_current:Bool is_upgrade:Bool last_transaction_id:string = PremiumStatePaymentOption;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge @custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format
emojiStatus custom_emoji_id:int64 = EmojiStatus;
@ -3814,7 +3821,7 @@ premiumFeaturePromotionAnimation feature:PremiumFeature animation:animation = Pr
//@state Text description of the state of the current Premium subscription; may be empty if the current user has no Telegram Premium subscription
//@payment_options The list of available options for buying Telegram Premium
//@animations The list of available promotion animations for Premium features
premiumState state:formattedText payment_options:vector<premiumPaymentOption> animations:vector<premiumFeaturePromotionAnimation> = PremiumState;
premiumState state:formattedText payment_options:vector<premiumStatePaymentOption> animations:vector<premiumFeaturePromotionAnimation> = PremiumState;
//@class StorePaymentPurpose @description Describes a purpose of an in-store payment

View File

@ -169,9 +169,9 @@ class GetPremiumPromoQuery final : public Td::ResultHandler {
}
auto period_options = get_premium_gift_options(std::move(promo->period_options_));
promise_.set_value(td_api::make_object<td_api::premiumState>(get_formatted_text_object(state, true, 0),
get_premium_payment_options_object(period_options),
std::move(animations)));
promise_.set_value(td_api::make_object<td_api::premiumState>(
get_formatted_text_object(state, true, 0), get_premium_state_payment_options_object(period_options),
std::move(animations)));
}
void on_error(Status status) final {

View File

@ -28,10 +28,13 @@ PremiumGiftOption::PremiumGiftOption(telegram_api::object_ptr<telegram_api::prem
PremiumGiftOption::PremiumGiftOption(telegram_api::object_ptr<telegram_api::premiumSubscriptionOption> &&option)
: months_(option->months_)
, is_current_(option->current_)
, is_upgrade_(option->can_purchase_upgrade_)
, currency_(std::move(option->currency_))
, amount_(option->amount_)
, bot_url_(std::move(option->bot_url_))
, store_product_(std::move(option->store_product_)) {
, store_product_(std::move(option->store_product_))
, transaction_(std::move(option->transaction_)) {
}
bool PremiumGiftOption::is_valid() const {
@ -65,6 +68,12 @@ td_api::object_ptr<td_api::premiumPaymentOption> PremiumGiftOption::get_premium_
link_type == nullptr ? nullptr : link_type->get_internal_link_type_object());
}
td_api::object_ptr<td_api::premiumStatePaymentOption> PremiumGiftOption::get_premium_state_payment_option_object(
const PremiumGiftOption &base_option) const {
return td_api::make_object<td_api::premiumStatePaymentOption>(get_premium_payment_option_object(base_option),
is_current_, is_upgrade_, transaction_);
}
bool operator<(const PremiumGiftOption &lhs, const PremiumGiftOption &rhs) {
return std::tie(lhs.months_, lhs.amount_, lhs.currency_, lhs.store_product_, lhs.bot_url_) <
std::tie(rhs.months_, rhs.amount_, rhs.currency_, rhs.store_product_, rhs.bot_url_);
@ -106,4 +115,15 @@ vector<td_api::object_ptr<td_api::premiumPaymentOption>> get_premium_payment_opt
});
}
vector<td_api::object_ptr<td_api::premiumStatePaymentOption>> get_premium_state_payment_options_object(
const vector<PremiumGiftOption> &options) {
if (options.empty()) {
return {};
}
auto base_premium_option_it = std::min_element(options.begin(), options.end());
return transform(options, [&base_premium_option_it](const auto &option) {
return option.get_premium_state_payment_option_object(*base_premium_option_it);
});
}
} // namespace td

View File

@ -15,10 +15,13 @@ namespace td {
class PremiumGiftOption {
int32 months_ = 0;
bool is_current_ = false;
bool is_upgrade_ = false;
string currency_;
int64 amount_ = 0;
string bot_url_;
string store_product_;
string transaction_;
friend bool operator<(const PremiumGiftOption &lhs, const PremiumGiftOption &rhs);
@ -34,6 +37,9 @@ class PremiumGiftOption {
td_api::object_ptr<td_api::premiumPaymentOption> get_premium_payment_option_object(
const PremiumGiftOption &base_option) const;
td_api::object_ptr<td_api::premiumStatePaymentOption> get_premium_state_payment_option_object(
const PremiumGiftOption &base_option) const;
bool is_valid() const;
template <class StorerT>
@ -55,4 +61,7 @@ vector<PremiumGiftOption> get_premium_gift_options(
vector<td_api::object_ptr<td_api::premiumPaymentOption>> get_premium_payment_options_object(
const vector<PremiumGiftOption> &options);
vector<td_api::object_ptr<td_api::premiumStatePaymentOption>> get_premium_state_payment_options_object(
const vector<PremiumGiftOption> &options);
} // namespace td

View File

@ -19,12 +19,16 @@ void PremiumGiftOption::store(StorerT &storer) const {
bool has_amount = amount_ != 0;
bool has_bot_url = !bot_url_.empty();
bool has_store_product = !store_product_.empty();
bool has_transaction = !transaction_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_months);
STORE_FLAG(has_currency);
STORE_FLAG(has_amount);
STORE_FLAG(has_bot_url);
STORE_FLAG(has_store_product);
STORE_FLAG(is_current_);
STORE_FLAG(is_upgrade_);
STORE_FLAG(has_transaction);
END_STORE_FLAGS();
if (has_months) {
td::store(months_, storer);
@ -41,6 +45,9 @@ void PremiumGiftOption::store(StorerT &storer) const {
if (has_store_product) {
td::store(store_product_, storer);
}
if (has_transaction) {
td::store(transaction_, storer);
}
}
template <class ParserT>
@ -50,12 +57,16 @@ void PremiumGiftOption::parse(ParserT &parser) {
bool has_amount;
bool has_bot_url;
bool has_store_product;
bool has_transaction;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_months);
PARSE_FLAG(has_currency);
PARSE_FLAG(has_amount);
PARSE_FLAG(has_bot_url);
PARSE_FLAG(has_store_product);
PARSE_FLAG(is_current_);
PARSE_FLAG(is_upgrade_);
PARSE_FLAG(has_transaction);
END_PARSE_FLAGS();
if (has_months) {
td::parse(months_, parser);
@ -72,6 +83,9 @@ void PremiumGiftOption::parse(ParserT &parser) {
if (has_store_product) {
td::parse(store_product_, parser);
}
if (has_transaction) {
td::parse(transaction_, parser);
}
}
} // namespace td