Allow to specify source in getPremiumFeatures.

This commit is contained in:
levlam 2022-05-24 02:19:30 +03:00
parent ab4a5d7499
commit 2d90ccc1bc
5 changed files with 121 additions and 6 deletions

View File

@ -2947,6 +2947,21 @@ premiumLimit type:PremiumLimitType default_value:int32 premium_value:int32 = Pre
premiumFeatures features:vector<PremiumFeature> limits:vector<premiumLimit> = PremiumFeatures;
//@class PremiumSource @description Describes a source, from which the Premium features screen is opened
//@description A limit was exceeded @limit_type Type of the exceeded limit
premiumSourceLimitExceeded limit_type:PremiumLimitType = PremiumSource;
//@description A user tried to use a Premium feature @feature The used feature
premiumSourceFeature feature:PremiumFeature = PremiumSource;
//@description A user opened an internal link of the type internalLinkTypePremiumFeatures @referrer The referrer from the link
premiumSourceLink referrer:string = PremiumSource;
//@description A user opened the Premium features screen from settings
premiumSourceSettings = PremiumSource;
//@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
@ -6300,8 +6315,8 @@ removeStickerFromSet sticker:InputFile = Ok;
getMapThumbnailFile location:location zoom:int32 width:int32 height:int32 scale:int32 chat_id:int53 = File;
//@description Returns information about features, available to Premium users
getPremiumFeatures = PremiumFeatures;
//@description Returns information about features, available to Premium users @source Source of the request; pass null if the method is called from some non-standard source
getPremiumFeatures source:PremiumSource = PremiumFeatures;
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier

View File

@ -26,7 +26,101 @@ const vector<Slice> &get_premium_limit_keys() {
return limit_keys;
}
void get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) {
static string get_premium_source(const td_api::PremiumLimitType *limit_type) {
if (limit_type == nullptr) {
return string();
}
auto key = [&]() {
switch (limit_type->get_id()) {
case td_api::premiumLimitTypeSupergroupCount::ID:
return "channels";
case td_api::premiumLimitTypeSavedAnimationCount::ID:
return "saved_gifs";
case td_api::premiumLimitTypeFavoriteStickerCount::ID:
return "stickers_faved";
case td_api::premiumLimitTypeChatFilterCount::ID:
return "dialog_filters";
case td_api::premiumLimitTypeChatFilterChosenChatCount::ID:
return "dialog_filters_chats";
case td_api::premiumLimitTypePinnedChatCount::ID:
return "dialogs_pinned";
case td_api::premiumLimitTypePinnedArchivedChatCount::ID:
return "dialogs_folder_pinned";
case td_api::premiumLimitTypeCreatedPublicChatCount::ID:
return "channels_public";
case td_api::premiumLimitTypeCaptionLength::ID:
return "caption_length";
default:
UNREACHABLE();
return "";
}
}();
return PSTRING() << "double_limits__" << key;
}
static string get_premium_source(const td_api::PremiumFeature *feature) {
if (feature == nullptr) {
return string();
}
switch (feature->get_id()) {
case td_api::premiumFeatureIncreasedLimits::ID:
return "double_limits";
case td_api::premiumFeatureIncreasedFileSize::ID:
return "more_upload";
case td_api::premiumFeatureImprovedDownloadSpeed::ID:
return "faster_download";
case td_api::premiumFeatureVoiceRecognition::ID:
return "voice_to_text";
case td_api::premiumFeatureDisabledAds::ID:
return "no_ads";
case td_api::premiumFeatureUniqueReactions::ID:
return "unique_reactions";
case td_api::premiumFeatureUniqueStickers::ID:
return "premium_stickers";
case td_api::premiumFeatureAdvancedChatManagement::ID:
return "advanced_chat_management";
case td_api::premiumFeatureProfileBadge::ID:
return "profile_badge";
case td_api::premiumFeatureAnimatedProfilePhoto::ID:
return "animated_userpics";
default:
UNREACHABLE();
}
return string();
}
static string get_premium_source(const td_api::object_ptr<td_api::PremiumSource> &source) {
if (source == nullptr) {
return string();
}
switch (source->get_id()) {
case td_api::premiumSourceLimitExceeded::ID: {
auto *limit_type = static_cast<const td_api::premiumSourceLimitExceeded *>(source.get())->limit_type_.get();
return get_premium_source(limit_type);
}
case td_api::premiumSourceFeature::ID: {
auto *feature = static_cast<const td_api::premiumSourceFeature *>(source.get())->feature_.get();
return get_premium_source(feature);
}
case td_api::premiumSourceLink::ID: {
auto &referrer = static_cast<const td_api::premiumSourceLink *>(source.get())->referrer_;
if (referrer.empty()) {
return "deeplink";
}
return PSTRING() << "deeplink_" << referrer;
}
case td_api::premiumSourceSettings::ID:
return "settings";
default:
UNREACHABLE();
return string();
}
}
void get_premium_features(const td_api::object_ptr<td_api::PremiumSource> &source,
Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) {
auto premium_features =
full_split(G()->shared_config().get_option_string(
"premium_features",
@ -113,6 +207,10 @@ void get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &
limits.push_back(td_api::make_object<td_api::premiumLimit>(std::move(type), default_limit, premium_limit));
}
}
auto source_str = get_premium_source(source);
// TODO use source_str
promise.set_value(td_api::make_object<td_api::premiumFeatures>(std::move(features), std::move(limits)));
}

View File

@ -17,6 +17,7 @@ namespace td {
const vector<Slice> &get_premium_limit_keys();
void get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise);
void get_premium_features(const td_api::object_ptr<td_api::PremiumSource> &source,
Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise);
} // namespace td

View File

@ -7829,7 +7829,7 @@ void Td::on_request(uint64 id, td_api::removeRecentHashtag &request) {
void Td::on_request(uint64 id, const td_api::getPremiumFeatures &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
get_premium_features(std::move(promise));
get_premium_features(request.source_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {

View File

@ -2544,7 +2544,8 @@ class CliClient final : public Actor {
} else if (op == "gadl") {
send_request(td_api::make_object<td_api::getApplicationDownloadLink>());
} else if (op == "gpfs") {
send_request(td_api::make_object<td_api::getPremiumFeatures>());
auto source = td_api::make_object<td_api::premiumSourceLink>("ref");
send_request(td_api::make_object<td_api::getPremiumFeatures>(std::move(source)));
} else if (op == "atos") {
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
} else if (op == "gdli") {