Add td_api::getPremiumState.
This commit is contained in:
parent
969322f32d
commit
7092674c05
@ -2974,6 +2974,17 @@ premiumSourceLink referrer:string = PremiumSource;
|
|||||||
premiumSourceSettings = PremiumSource;
|
premiumSourceSettings = PremiumSource;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Describes a promotion video for a Premium feature @feature Premium feature @video Promotion video for the feature
|
||||||
|
premiumFeaturePromotionVideo feature:PremiumFeature video:video = PremiumFeaturePromotionVideo;
|
||||||
|
|
||||||
|
//@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
|
||||||
|
//@videos The list of available promotion videos for Premium features
|
||||||
|
premiumState state:formattedText currency:string monthly_amount:int53 videos:vector<premiumFeaturePromotionVideo> = PremiumState;
|
||||||
|
|
||||||
|
|
||||||
//@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org
|
//@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org
|
||||||
|
|
||||||
//@description A token for Firebase Cloud Messaging @token Device registration token; may be empty to deregister a device @encrypt True, if push notifications must be additionally encrypted
|
//@description A token for Firebase Cloud Messaging @token Device registration token; may be empty to deregister a device @encrypt True, if push notifications must be additionally encrypted
|
||||||
@ -4986,7 +4997,7 @@ editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup =
|
|||||||
editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok;
|
editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok;
|
||||||
|
|
||||||
|
|
||||||
//@description Returns reactions, which can be added to a message. The list can change after updateReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message. The method will return Premium reactions, even the current user has no Premium account
|
//@description Returns reactions, which can be added to a message. The list can change after updateReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message. The method will return Premium reactions, even the current user has no Premium subscription
|
||||||
//@chat_id Identifier of the chat to which the message belongs
|
//@chat_id Identifier of the chat to which the message belongs
|
||||||
//@message_id Identifier of the message
|
//@message_id Identifier of the message
|
||||||
getMessageAvailableReactions chat_id:int53 message_id:int53 = AvailableReactions;
|
getMessageAvailableReactions chat_id:int53 message_id:int53 = AvailableReactions;
|
||||||
@ -6347,6 +6358,9 @@ viewPremiumFeature feature:PremiumFeature = Ok;
|
|||||||
//@description Informs TDLib that the user clicked Premium subscription button on the Premium features screen
|
//@description Informs TDLib that the user clicked Premium subscription button on the Premium features screen
|
||||||
clickPremiumSubscriptionButton = Ok;
|
clickPremiumSubscriptionButton = Ok;
|
||||||
|
|
||||||
|
//@description Returns state of Telegram Premium subscription and promotion videos for Premium features
|
||||||
|
getPremiumState = PremiumState;
|
||||||
|
|
||||||
|
|
||||||
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier
|
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier
|
||||||
acceptTermsOfService terms_of_service_id:string = Ok;
|
acceptTermsOfService terms_of_service_id:string = Ok;
|
||||||
|
@ -8,13 +8,124 @@
|
|||||||
|
|
||||||
#include "td/telegram/Application.h"
|
#include "td/telegram/Application.h"
|
||||||
#include "td/telegram/ConfigShared.h"
|
#include "td/telegram/ConfigShared.h"
|
||||||
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
|
#include "td/telegram/MessageEntity.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/VideosManager.h"
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/SliceBuilder.h"
|
#include "td/utils/SliceBuilder.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
static td_api::object_ptr<td_api::PremiumFeature> get_premium_feature_object(Slice premium_feature) {
|
||||||
|
if (premium_feature == "double_limits") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureIncreasedLimits>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "more_upload") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureIncreasedUploadFileSize>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "faster_download") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureImprovedDownloadSpeed>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "voice_to_text") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureVoiceRecognition>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "no_ads") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureDisabledAds>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "unique_reactions") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureUniqueReactions>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "premium_stickers") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureUniqueStickers>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "advanced_chat_management") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureAdvancedChatManagement>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "profile_badge") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureProfileBadge>();
|
||||||
|
}
|
||||||
|
if (premium_feature == "animated_userpics") {
|
||||||
|
return td_api::make_object<td_api::premiumFeatureAnimatedProfilePhoto>();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetPremiumPromoQuery final : public Td::ResultHandler {
|
||||||
|
Promise<td_api::object_ptr<td_api::premiumState>> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetPremiumPromoQuery(Promise<td_api::object_ptr<td_api::premiumState>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send() {
|
||||||
|
send_query(G()->net_query_creator().create(telegram_api::help_getPremiumPromo()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::help_getPremiumPromo>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto promo = result_ptr.move_as_ok();
|
||||||
|
LOG(INFO) << "Receive result for GetPremiumPromoQuery: " << to_string(promo);
|
||||||
|
|
||||||
|
auto state = get_message_text(td_->contacts_manager_.get(), std::move(promo->status_text_),
|
||||||
|
std::move(promo->status_entities_), true, true, 0, false, "GetPremiumPromoQuery");
|
||||||
|
|
||||||
|
if (promo->video_sections_.size() != promo->videos_.size()) {
|
||||||
|
return on_error(Status::Error(500, "Receive wrong number of videos"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (promo->monthly_amount_ < 0 || promo->monthly_amount_ > 9999'9999'9999) {
|
||||||
|
return on_error(Status::Error(500, "Receive invalid monthly amount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (promo->currency_.size() != 3) {
|
||||||
|
return on_error(Status::Error(500, "Receive invalid currency"));
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<td_api::object_ptr<td_api::premiumFeaturePromotionVideo>> videos;
|
||||||
|
for (size_t i = 0; i < promo->video_sections_.size(); i++) {
|
||||||
|
auto feature = get_premium_feature_object(promo->video_sections_[i]);
|
||||||
|
if (feature == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto video = std::move(promo->videos_[i]);
|
||||||
|
if (video->get_id() != telegram_api::document::ID) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(video) << " for " << promo->video_sections_[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto parsed_document = td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(video),
|
||||||
|
DialogId(), nullptr, Document::Type::Video);
|
||||||
|
|
||||||
|
if (parsed_document.type != Document::Type::Video) {
|
||||||
|
LOG(ERROR) << "Receive " << parsed_document.type << " for " << promo->video_sections_[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto video_object = td_->videos_manager_->get_video_object(parsed_document.file_id);
|
||||||
|
videos.push_back(
|
||||||
|
td_api::make_object<td_api::premiumFeaturePromotionVideo>(std::move(feature), std::move(video_object)));
|
||||||
|
}
|
||||||
|
|
||||||
|
promise_.set_value(td_api::make_object<td_api::premiumState>(get_formatted_text_object(state, true, 0),
|
||||||
|
std::move(promo->currency_), promo->monthly_amount_,
|
||||||
|
std::move(videos)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const vector<Slice> &get_premium_limit_keys() {
|
const vector<Slice> &get_premium_limit_keys() {
|
||||||
static const vector<Slice> limit_keys{"channels",
|
static const vector<Slice> limit_keys{"channels",
|
||||||
"saved_gifs",
|
"saved_gifs",
|
||||||
@ -190,39 +301,7 @@ void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource
|
|||||||
',');
|
',');
|
||||||
vector<td_api::object_ptr<td_api::PremiumFeature>> features;
|
vector<td_api::object_ptr<td_api::PremiumFeature>> features;
|
||||||
for (const auto &premium_feature : premium_features) {
|
for (const auto &premium_feature : premium_features) {
|
||||||
auto feature = [&]() -> td_api::object_ptr<td_api::PremiumFeature> {
|
auto feature = get_premium_feature_object(premium_feature);
|
||||||
if (premium_feature == "double_limits") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureIncreasedLimits>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "more_upload") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureIncreasedUploadFileSize>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "faster_download") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureImprovedDownloadSpeed>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "voice_to_text") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureVoiceRecognition>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "no_ads") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureDisabledAds>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "unique_reactions") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureUniqueReactions>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "premium_stickers") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureUniqueStickers>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "advanced_chat_management") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureAdvancedChatManagement>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "profile_badge") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureProfileBadge>();
|
|
||||||
}
|
|
||||||
if (premium_feature == "animated_userpics") {
|
|
||||||
return td_api::make_object<td_api::premiumFeatureAnimatedProfilePhoto>();
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}();
|
|
||||||
if (feature != nullptr) {
|
if (feature != nullptr) {
|
||||||
features.push_back(std::move(feature));
|
features.push_back(std::move(feature));
|
||||||
}
|
}
|
||||||
@ -280,4 +359,8 @@ void click_premium_subscription_button(Td *td, Promise<Unit> &&promise) {
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise) {
|
||||||
|
td->create_handler<GetPremiumPromoQuery>(std::move(promise))->send();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -29,4 +29,6 @@ void view_premium_feature(Td *td, const td_api::object_ptr<td_api::PremiumFeatur
|
|||||||
|
|
||||||
void click_premium_subscription_button(Td *td, Promise<Unit> &&promise);
|
void click_premium_subscription_button(Td *td, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -7867,6 +7867,12 @@ void Td::on_request(uint64 id, const td_api::clickPremiumSubscriptionButton &req
|
|||||||
click_premium_subscription_button(this, std::move(promise));
|
click_premium_subscription_button(this, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::getPremiumState &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_REQUEST_PROMISE();
|
||||||
|
get_premium_state(this, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
|
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CLEAN_INPUT_STRING(request.terms_of_service_id_);
|
CLEAN_INPUT_STRING(request.terms_of_service_id_);
|
||||||
|
@ -1301,6 +1301,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::clickPremiumSubscriptionButton &request);
|
void on_request(uint64 id, const td_api::clickPremiumSubscriptionButton &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::getPremiumState &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::acceptTermsOfService &request);
|
void on_request(uint64 id, td_api::acceptTermsOfService &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getCountries &request);
|
void on_request(uint64 id, const td_api::getCountries &request);
|
||||||
|
@ -2555,6 +2555,8 @@ class CliClient final : public Actor {
|
|||||||
send_request(td_api::make_object<td_api::viewPremiumFeature>(std::move(feature)));
|
send_request(td_api::make_object<td_api::viewPremiumFeature>(std::move(feature)));
|
||||||
} else if (op == "cprsb") {
|
} else if (op == "cprsb") {
|
||||||
send_request(td_api::make_object<td_api::clickPremiumSubscriptionButton>());
|
send_request(td_api::make_object<td_api::clickPremiumSubscriptionButton>());
|
||||||
|
} else if (op == "gprs") {
|
||||||
|
send_request(td_api::make_object<td_api::getPremiumState>());
|
||||||
} else if (op == "atos") {
|
} else if (op == "atos") {
|
||||||
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
|
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
|
||||||
} else if (op == "gdli") {
|
} else if (op == "gdli") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user