From ab4a5d74993923ed890535ce0040cdfe5b167982 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 May 2022 01:36:55 +0300 Subject: [PATCH] Move get_premium_features to Premium.h. --- td/telegram/ConfigManager.cpp | 90 --------------------------------- td/telegram/ConfigManager.h | 2 - td/telegram/Premium.cpp | 95 +++++++++++++++++++++++++++++++++++ td/telegram/Premium.h | 6 +++ td/telegram/Td.cpp | 3 +- 5 files changed, 103 insertions(+), 93 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 314b85a5b..23323041b 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1135,96 +1135,6 @@ void ConfigManager::dismiss_suggested_action(SuggestedAction suggested_action, P } } -void ConfigManager::get_premium_features(Promise> &&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> features; - for (const auto &premium_feature : premium_features) { - auto feature = [&]() -> td_api::object_ptr { - if (premium_feature == "double_limits") { - return td_api::make_object(); - } - if (premium_feature == "more_upload") { - return td_api::make_object(); - } - if (premium_feature == "faster_download") { - return td_api::make_object(); - } - if (premium_feature == "voice_to_text") { - return td_api::make_object(); - } - if (premium_feature == "no_ads") { - return td_api::make_object(); - } - if (premium_feature == "unique_reactions") { - return td_api::make_object(); - } - if (premium_feature == "premium_stickers") { - return td_api::make_object(); - } - if (premium_feature == "advanced_chat_management") { - return td_api::make_object(); - } - if (premium_feature == "profile_badge") { - return td_api::make_object(); - } - if (premium_feature == "animated_userpics") { - return td_api::make_object(); - } - return nullptr; - }(); - if (feature != nullptr) { - features.push_back(std::move(feature)); - } - } - - auto &limit_keys = get_premium_limit_keys(); - vector> limits; - for (auto key : limit_keys) { - int32 default_limit = static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_default")); - int32 premium_limit = static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_premium")); - if (default_limit > 0 && premium_limit > 0) { - auto type = [&]() -> td_api::object_ptr { - if (key == "channels_limit") { - return td_api::make_object(); - } - if (key == "saved_gifs_limit") { - return td_api::make_object(); - } - if (key == "stickers_faved_limit") { - return td_api::make_object(); - } - if (key == "dialog_filters_limit") { - return td_api::make_object(); - } - if (key == "dialog_filters_chats_limit") { - return td_api::make_object(); - } - if (key == "dialogs_pinned_limit") { - return td_api::make_object(); - } - if (key == "dialogs_folder_pinned_limit") { - return td_api::make_object(); - } - if (key == "channels_public_limit") { - return td_api::make_object(); - } - if (key == "caption_length_limit") { - return td_api::make_object(); - } - UNREACHABLE(); - return nullptr; - }(); - limits.push_back(td_api::make_object(std::move(type), default_limit, premium_limit)); - } - } - promise.set_value(td_api::make_object(std::move(features), std::move(limits))); -} - void ConfigManager::on_result(NetQueryPtr res) { auto token = get_link_token(); if (token >= 100 && token <= 200) { diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 3030a2bf6..472982cea 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -103,8 +103,6 @@ class ConfigManager final : public NetQueryCallback { void on_dc_options_update(DcOptions dc_options); - void get_premium_features(Promise> &&promise); - void get_current_state(vector> &updates) const; private: diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index 43eff30e3..1d25d8f0b 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -6,6 +6,11 @@ // #include "td/telegram/Premium.h" +#include "td/telegram/ConfigShared.h" +#include "td/telegram/Global.h" + +#include "td/utils/SliceBuilder.h" + namespace td { const vector &get_premium_limit_keys() { @@ -21,4 +26,94 @@ const vector &get_premium_limit_keys() { return limit_keys; } +void get_premium_features(Promise> &&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> features; + for (const auto &premium_feature : premium_features) { + auto feature = [&]() -> td_api::object_ptr { + if (premium_feature == "double_limits") { + return td_api::make_object(); + } + if (premium_feature == "more_upload") { + return td_api::make_object(); + } + if (premium_feature == "faster_download") { + return td_api::make_object(); + } + if (premium_feature == "voice_to_text") { + return td_api::make_object(); + } + if (premium_feature == "no_ads") { + return td_api::make_object(); + } + if (premium_feature == "unique_reactions") { + return td_api::make_object(); + } + if (premium_feature == "premium_stickers") { + return td_api::make_object(); + } + if (premium_feature == "advanced_chat_management") { + return td_api::make_object(); + } + if (premium_feature == "profile_badge") { + return td_api::make_object(); + } + if (premium_feature == "animated_userpics") { + return td_api::make_object(); + } + return nullptr; + }(); + if (feature != nullptr) { + features.push_back(std::move(feature)); + } + } + + auto &limit_keys = get_premium_limit_keys(); + vector> limits; + for (auto key : limit_keys) { + int32 default_limit = static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_default")); + int32 premium_limit = static_cast(G()->shared_config().get_option_integer(PSLICE() << key << "_premium")); + if (default_limit > 0 && premium_limit > 0) { + auto type = [&]() -> td_api::object_ptr { + if (key == "channels_limit") { + return td_api::make_object(); + } + if (key == "saved_gifs_limit") { + return td_api::make_object(); + } + if (key == "stickers_faved_limit") { + return td_api::make_object(); + } + if (key == "dialog_filters_limit") { + return td_api::make_object(); + } + if (key == "dialog_filters_chats_limit") { + return td_api::make_object(); + } + if (key == "dialogs_pinned_limit") { + return td_api::make_object(); + } + if (key == "dialogs_folder_pinned_limit") { + return td_api::make_object(); + } + if (key == "channels_public_limit") { + return td_api::make_object(); + } + if (key == "caption_length_limit") { + return td_api::make_object(); + } + UNREACHABLE(); + return nullptr; + }(); + limits.push_back(td_api::make_object(std::move(type), default_limit, premium_limit)); + } + } + promise.set_value(td_api::make_object(std::move(features), std::move(limits))); +} + } // namespace td diff --git a/td/telegram/Premium.h b/td/telegram/Premium.h index 6d0a459a3..69f1eccd4 100644 --- a/td/telegram/Premium.h +++ b/td/telegram/Premium.h @@ -6,6 +6,10 @@ // #pragma once +#include "td/telegram/td_api.h" + +#include "td/actor/PromiseFuture.h" + #include "td/utils/common.h" #include "td/utils/Slice.h" @@ -13,4 +17,6 @@ namespace td { const vector &get_premium_limit_keys(); +void get_premium_features(Promise> &&promise); + } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 32a6adb21..3c6b0c87d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -95,6 +95,7 @@ #include "td/telegram/Photo.h" #include "td/telegram/PhotoSizeSource.h" #include "td/telegram/PollManager.h" +#include "td/telegram/Premium.h" #include "td/telegram/PrivacyManager.h" #include "td/telegram/PublicDialogType.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) { CHECK_IS_USER(); 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) {