Add suggestedActionUpgradePremium.

This commit is contained in:
levlam 2023-01-23 16:03:32 +03:00
parent 136a50d0ae
commit 4a5b702f11
4 changed files with 22 additions and 1 deletions

View File

@ -4868,6 +4868,9 @@ suggestedActionConvertToBroadcastGroup supergroup_id:int53 = SuggestedAction;
//@authorization_delay The number of days to pass between consecutive authorizations if the user declines to set password; if 0, then the user is advised to set the password for security reasons //@authorization_delay The number of days to pass between consecutive authorizations if the user declines to set password; if 0, then the user is advised to set the password for security reasons
suggestedActionSetPassword authorization_delay:int32 = SuggestedAction; suggestedActionSetPassword authorization_delay:int32 = SuggestedAction;
//@description Suggests the user to upgrade Premium subscription from monthly payments to annual payments
suggestedActionUpgradePremium = SuggestedAction;
//@description Contains a counter @count Count //@description Contains a counter @count Count
count count:int32 = Count; count count:int32 = Count;

View File

@ -16,6 +16,7 @@
#include "td/telegram/MessageEntity.h" #include "td/telegram/MessageEntity.h"
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
#include "td/telegram/PremiumGiftOption.h" #include "td/telegram/PremiumGiftOption.h"
#include "td/telegram/SuggestedAction.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/UpdatesManager.h" #include "td/telegram/UpdatesManager.h"
@ -535,6 +536,9 @@ void can_purchase_premium(Td *td, td_api::object_ptr<td_api::StorePaymentPurpose
void assign_app_store_transaction(Td *td, const string &receipt, void assign_app_store_transaction(Td *td, const string &receipt,
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) { td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) {
if (purpose != nullptr && purpose->get_id() == td_api::storePaymentPurposePremiumSubscription::ID) {
dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::UpgradePremium}, Promise<Unit>());
}
td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, std::move(purpose)); td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, std::move(purpose));
} }
@ -542,6 +546,9 @@ void assign_play_market_transaction(Td *td, const string &package_name, const st
const string &purchase_token, const string &purchase_token,
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
if (purpose != nullptr && purpose->get_id() == td_api::storePaymentPurposePremiumSubscription::ID) {
dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::UpgradePremium}, Promise<Unit>());
}
td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise)) td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise))
->send(package_name, store_product_id, purchase_token, std::move(purpose)); ->send(package_name, store_product_id, purchase_token, std::move(purpose));
} }

View File

@ -37,6 +37,8 @@ SuggestedAction::SuggestedAction(Slice action_str) {
init(Type::ViewChecksHint); init(Type::ViewChecksHint);
} else if (action_str == Slice("SETUP_PASSWORD")) { } else if (action_str == Slice("SETUP_PASSWORD")) {
init(Type::SetPassword); init(Type::SetPassword);
} else if (action_str == Slice("PREMIUM_UPGRADE")) {
init(Type::UpgradePremium);
} }
} }
@ -80,6 +82,9 @@ SuggestedAction::SuggestedAction(const td_api::object_ptr<td_api::SuggestedActio
otherwise_relogin_days_ = action->authorization_delay_; otherwise_relogin_days_ = action->authorization_delay_;
break; break;
} }
case td_api::suggestedActionUpgradePremium::ID:
init(Type::UpgradePremium);
break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
@ -99,6 +104,8 @@ string SuggestedAction::get_suggested_action_str() const {
return "CONVERT_GIGAGROUP"; return "CONVERT_GIGAGROUP";
case Type::SetPassword: case Type::SetPassword:
return "SETUP_PASSWORD"; return "SETUP_PASSWORD";
case Type::UpgradePremium:
return "PREMIUM_UPGRADE";
default: default:
return string(); return string();
} }
@ -120,6 +127,8 @@ td_api::object_ptr<td_api::SuggestedAction> SuggestedAction::get_suggested_actio
return td_api::make_object<td_api::suggestedActionConvertToBroadcastGroup>(dialog_id_.get_channel_id().get()); return td_api::make_object<td_api::suggestedActionConvertToBroadcastGroup>(dialog_id_.get_channel_id().get());
case Type::SetPassword: case Type::SetPassword:
return td_api::make_object<td_api::suggestedActionSetPassword>(otherwise_relogin_days_); return td_api::make_object<td_api::suggestedActionSetPassword>(otherwise_relogin_days_);
case Type::UpgradePremium:
return td_api::make_object<td_api::suggestedActionUpgradePremium>();
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
@ -178,6 +187,7 @@ void dismiss_suggested_action(SuggestedAction action, Promise<Unit> &&promise) {
case SuggestedAction::Type::CheckPassword: case SuggestedAction::Type::CheckPassword:
case SuggestedAction::Type::CheckPhoneNumber: case SuggestedAction::Type::CheckPhoneNumber:
case SuggestedAction::Type::ViewChecksHint: case SuggestedAction::Type::ViewChecksHint:
case SuggestedAction::Type::UpgradePremium:
return send_closure_later(G()->config_manager(), &ConfigManager::dismiss_suggested_action, std::move(action), return send_closure_later(G()->config_manager(), &ConfigManager::dismiss_suggested_action, std::move(action),
std::move(promise)); std::move(promise));
case SuggestedAction::Type::ConvertToGigagroup: case SuggestedAction::Type::ConvertToGigagroup:

View File

@ -23,7 +23,8 @@ struct SuggestedAction {
ViewChecksHint, ViewChecksHint,
ConvertToGigagroup, ConvertToGigagroup,
CheckPassword, CheckPassword,
SetPassword SetPassword,
UpgradePremium
}; };
Type type_ = Type::Empty; Type type_ = Type::Empty;
DialogId dialog_id_; DialogId dialog_id_;