Move get_premium_features to Premium.h.
This commit is contained in:
parent
23e9f03d70
commit
ab4a5d7499
@ -1135,96 +1135,6 @@ 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto &limit_keys = get_premium_limit_keys();
|
|
||||||
vector<td_api::object_ptr<td_api::premiumLimit>> limits;
|
|
||||||
for (auto key : limit_keys) {
|
|
||||||
int32 default_limit = static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_default"));
|
|
||||||
int32 premium_limit = static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_premium"));
|
|
||||||
if (default_limit > 0 && premium_limit > 0) {
|
|
||||||
auto type = [&]() -> td_api::object_ptr<td_api::PremiumLimitType> {
|
|
||||||
if (key == "channels_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeSupergroupCount>();
|
|
||||||
}
|
|
||||||
if (key == "saved_gifs_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeSavedAnimationCount>();
|
|
||||||
}
|
|
||||||
if (key == "stickers_faved_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeFavoriteStickerCount>();
|
|
||||||
}
|
|
||||||
if (key == "dialog_filters_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeChatFilterCount>();
|
|
||||||
}
|
|
||||||
if (key == "dialog_filters_chats_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeChatFilterChosenChatCount>();
|
|
||||||
}
|
|
||||||
if (key == "dialogs_pinned_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypePinnedChatCount>();
|
|
||||||
}
|
|
||||||
if (key == "dialogs_folder_pinned_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypePinnedArchivedChatCount>();
|
|
||||||
}
|
|
||||||
if (key == "channels_public_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeCreatedPublicChatCount>();
|
|
||||||
}
|
|
||||||
if (key == "caption_length_limit") {
|
|
||||||
return td_api::make_object<td_api::premiumLimitTypeCaptionLength>();
|
|
||||||
}
|
|
||||||
UNREACHABLE();
|
|
||||||
return nullptr;
|
|
||||||
}();
|
|
||||||
limits.push_back(td_api::make_object<td_api::premiumLimit>(std::move(type), default_limit, premium_limit));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
promise.set_value(td_api::make_object<td_api::premiumFeatures>(std::move(features), std::move(limits)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigManager::on_result(NetQueryPtr res) {
|
void ConfigManager::on_result(NetQueryPtr res) {
|
||||||
auto token = get_link_token();
|
auto token = get_link_token();
|
||||||
if (token >= 100 && token <= 200) {
|
if (token >= 100 && token <= 200) {
|
||||||
|
@ -103,8 +103,6 @@ class ConfigManager final : public NetQueryCallback {
|
|||||||
|
|
||||||
void on_dc_options_update(DcOptions dc_options);
|
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;
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/Premium.h"
|
#include "td/telegram/Premium.h"
|
||||||
|
|
||||||
|
#include "td/telegram/ConfigShared.h"
|
||||||
|
#include "td/telegram/Global.h"
|
||||||
|
|
||||||
|
#include "td/utils/SliceBuilder.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
const vector<Slice> &get_premium_limit_keys() {
|
const vector<Slice> &get_premium_limit_keys() {
|
||||||
@ -21,4 +26,94 @@ const vector<Slice> &get_premium_limit_keys() {
|
|||||||
return limit_keys;
|
return limit_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &limit_keys = get_premium_limit_keys();
|
||||||
|
vector<td_api::object_ptr<td_api::premiumLimit>> limits;
|
||||||
|
for (auto key : limit_keys) {
|
||||||
|
int32 default_limit = static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_default"));
|
||||||
|
int32 premium_limit = static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_premium"));
|
||||||
|
if (default_limit > 0 && premium_limit > 0) {
|
||||||
|
auto type = [&]() -> td_api::object_ptr<td_api::PremiumLimitType> {
|
||||||
|
if (key == "channels_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeSupergroupCount>();
|
||||||
|
}
|
||||||
|
if (key == "saved_gifs_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeSavedAnimationCount>();
|
||||||
|
}
|
||||||
|
if (key == "stickers_faved_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeFavoriteStickerCount>();
|
||||||
|
}
|
||||||
|
if (key == "dialog_filters_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeChatFilterCount>();
|
||||||
|
}
|
||||||
|
if (key == "dialog_filters_chats_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeChatFilterChosenChatCount>();
|
||||||
|
}
|
||||||
|
if (key == "dialogs_pinned_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypePinnedChatCount>();
|
||||||
|
}
|
||||||
|
if (key == "dialogs_folder_pinned_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypePinnedArchivedChatCount>();
|
||||||
|
}
|
||||||
|
if (key == "channels_public_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeCreatedPublicChatCount>();
|
||||||
|
}
|
||||||
|
if (key == "caption_length_limit") {
|
||||||
|
return td_api::make_object<td_api::premiumLimitTypeCaptionLength>();
|
||||||
|
}
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}();
|
||||||
|
limits.push_back(td_api::make_object<td_api::premiumLimit>(std::move(type), default_limit, premium_limit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
promise.set_value(td_api::make_object<td_api::premiumFeatures>(std::move(features), std::move(limits)));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
|
||||||
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
@ -13,4 +17,6 @@ namespace td {
|
|||||||
|
|
||||||
const vector<Slice> &get_premium_limit_keys();
|
const vector<Slice> &get_premium_limit_keys();
|
||||||
|
|
||||||
|
void get_premium_features(Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -95,6 +95,7 @@
|
|||||||
#include "td/telegram/Photo.h"
|
#include "td/telegram/Photo.h"
|
||||||
#include "td/telegram/PhotoSizeSource.h"
|
#include "td/telegram/PhotoSizeSource.h"
|
||||||
#include "td/telegram/PollManager.h"
|
#include "td/telegram/PollManager.h"
|
||||||
|
#include "td/telegram/Premium.h"
|
||||||
#include "td/telegram/PrivacyManager.h"
|
#include "td/telegram/PrivacyManager.h"
|
||||||
#include "td/telegram/PublicDialogType.h"
|
#include "td/telegram/PublicDialogType.h"
|
||||||
#include "td/telegram/ReportReason.h"
|
#include "td/telegram/ReportReason.h"
|
||||||
@ -7828,7 +7829,7 @@ void Td::on_request(uint64 id, td_api::removeRecentHashtag &request) {
|
|||||||
void Td::on_request(uint64 id, const td_api::getPremiumFeatures &request) {
|
void Td::on_request(uint64 id, const td_api::getPremiumFeatures &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
send_closure(G()->config_manager(), &ConfigManager::get_premium_features, std::move(promise));
|
get_premium_features(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
|
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user