Add td_api::getPremiumFeatures.

This commit is contained in:
levlam 2022-05-23 15:56:31 +03:00
parent e9a8d43a0a
commit 2166f80ccb
7 changed files with 123 additions and 2 deletions

View File

@ -2505,7 +2505,7 @@ availableReactions reactions:vector<string> = AvailableReactions;
//@reaction Text representation of the reaction
//@title Reaction title
//@is_active True, if the reaction can be added to new messages and enabled in chats
//@is_premium True, if the reaction is available only for premium users
//@is_premium True, if the reaction is available only for Premium users
//@static_icon Static icon for the reaction
//@appear_animation Appear animation for the reaction
//@select_animation Select animation for the reaction
@ -2877,6 +2877,43 @@ languagePackInfo id:string base_language_pack_id:string name:string native_name:
localizationTargetInfo language_packs:vector<languagePackInfo> = LocalizationTargetInfo;
//@class PremiumFeature @description Describes a feature available to Premium users
//@description Increased limits
premiumFeatureIncreasedLimits = PremiumFeature;
//@description Increased maximum uploaded file size
premiumFeatureIncreasedFileSize = PremiumFeature;
//@description Improved download speed
premiumFeatureImprovedDownloadSpeed = PremiumFeature;
//@description The ability to convert voice notes to text
premiumFeatureVoiceRecognition = PremiumFeature;
//@description Disabled ads
premiumFeatureDisabledAds = PremiumFeature;
//@description Allowed to use more reactions
premiumFeatureUniqueReactions = PremiumFeature;
//@description Allowed to use premium stickers with unique effects
premiumFeatureUniqueStickers = PremiumFeature;
//@description Ability to change position of the main chat list, archive and mute all new chats from non-contacts, and completely disable notifications about the user's contacts joined Telegram
premiumFeatureAdvancedChatManagement = PremiumFeature;
//@description A badge in the user's profile
premiumFeatureProfileBadge = PremiumFeature;
//@description Profile photo animation on message and chat screens
premiumFeatureAnimatedProfilePhoto = PremiumFeature;
//@description Contains information about features, available to Premium users @features The list of available features
premiumFeatures features:vector<PremiumFeature> = PremiumFeatures;
//@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
@ -5144,7 +5181,7 @@ editChatFilter chat_filter_id:int32 filter:chatFilter = ChatFilterInfo;
//@description Deletes existing chat filter @chat_filter_id Chat filter identifier
deleteChatFilter chat_filter_id:int32 = Ok;
//@description Changes the order of chat filters @chat_filter_ids Identifiers of chat filters in the new correct order @main_chat_list_position Position of the main chat list among chat filters, 0-based. Can be non-zero only for premium users
//@description Changes the order of chat filters @chat_filter_ids Identifiers of chat filters in the new correct order @main_chat_list_position Position of the main chat list among chat filters, 0-based. Can be non-zero only for Premium users
reorderChatFilters chat_filter_ids:vector<int32> main_chat_list_position:int32 = Ok;
//@description Returns recommended chat filters for the current user
@ -6227,6 +6264,10 @@ 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 Accepts Telegram terms of services @terms_of_service_id Terms of service identifier
acceptTermsOfService terms_of_service_id:string = Ok;

View File

@ -1134,6 +1134,55 @@ void ConfigManager::dismiss_suggested_action(SuggestedAction suggested_action, P
}
}
void ConfigManager::get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) {
auto premium_features =
full_split(G()->shared_config().get_option_string(
"premium_features",
"double_limits,more_upload,faster_download,voice_to_text,no_ads,unique_reactions,premium_stickers,"
"advanced_chat_management,profile_badge,animated_userpics"),
',');
vector<td_api::object_ptr<td_api::PremiumFeature>> features;
for (const auto &premium_feature : premium_features) {
auto feature = [&]() -> td_api::object_ptr<td_api::PremiumFeature> {
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::premiumFeatureIncreasedFileSize>();
}
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) {
features.push_back(std::move(feature));
}
}
promise.set_value(td_api::make_object<td_api::premiumFeatures>(std::move(features)));
}
void ConfigManager::on_result(NetQueryPtr res) {
auto token = get_link_token();
if (token >= 100 && token <= 200) {
@ -1472,6 +1521,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
double animated_emoji_zoom = 0.0;
string default_reaction;
int64 reactions_uniq_max = 0;
vector<string> premium_features;
if (config->get_id() == telegram_api::jsonObject::ID) {
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
Slice key = key_value->key_;
@ -1733,6 +1783,20 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
G()->shared_config().set_option_integer("notification_sound_count_max", setting_value);
continue;
}
if (key == "premium_promo_order") {
if (value->get_id() == telegram_api::jsonArray::ID) {
auto features = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
for (auto &feature : features) {
auto premium_feature = get_json_value_string(std::move(feature), key);
if (!td::contains(premium_feature, ',')) {
premium_features.push_back(std::move(premium_feature));
}
}
} else {
LOG(ERROR) << "Receive unexpected premium_promo_order " << to_string(*value);
}
continue;
}
new_values.push_back(std::move(key_value));
}
@ -1816,6 +1880,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
shared_config.set_option_integer("reactions_uniq_max", reactions_uniq_max);
}
shared_config.set_option_string("premium_features", implode(premium_features, ','));
shared_config.set_option_empty("default_ton_blockchain_config");
shared_config.set_option_empty("default_ton_blockchain_name");

View File

@ -103,6 +103,8 @@ class ConfigManager final : public NetQueryCallback {
void on_dc_options_update(DcOptions dc_options);
void get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private:

View File

@ -173,6 +173,8 @@ bool OptionManager::is_internal_option(Slice name) {
return name == "notification_cloud_delay_ms" || name == "notification_default_delay_ms";
case 'o':
return name == "online_cloud_timeout_ms" || name == "online_update_period_ms" || name == "otherwise_relogin_days";
case 'p':
return name == "premium_features";
case 'r':
return name == "rating_e_decay" || name == "reactions_uniq_max" || name == "recent_stickers_limit" ||
name == "revoke_pm_inbox" || name == "revoke_time_limit" || name == "revoke_pm_time_limit";

View File

@ -7825,6 +7825,12 @@ void Td::on_request(uint64 id, td_api::removeRecentHashtag &request) {
send_closure(hashtag_hints_, &HashtagHints::remove_hashtag, std::move(request.hashtag_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getPremiumFeatures &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
send_closure(G()->config_manager(), &ConfigManager::get_premium_features, std::move(promise));
}
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.terms_of_service_id_);

View File

@ -1288,6 +1288,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::removeRecentHashtag &request);
void on_request(uint64 id, const td_api::getPremiumFeatures &request);
void on_request(uint64 id, td_api::acceptTermsOfService &request);
void on_request(uint64 id, const td_api::getCountries &request);

View File

@ -2543,6 +2543,8 @@ class CliClient final : public Actor {
execute(td_api::make_object<td_api::getPhoneNumberInfoSync>(rand_bool() ? "en" : "", args));
} 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>());
} else if (op == "atos") {
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
} else if (op == "gdli") {