Always update premium-dependent options.

This commit is contained in:
levlam 2023-12-08 12:57:13 +03:00
parent 44844e1c19
commit 559cbe5de9
4 changed files with 52 additions and 57 deletions

View File

@ -23,6 +23,7 @@
#include "td/telegram/net/NetType.h"
#include "td/telegram/net/PublicRsaKeyShared.h"
#include "td/telegram/net/Session.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/Premium.h"
#include "td/telegram/ReactionType.h"
#include "td/telegram/StateManager.h"
@ -1231,6 +1232,7 @@ void ConfigManager::on_result(NetQueryPtr net_query) {
CHECK(app_config_.config_ != nullptr);
G()->td_db()->get_binlog_pmc()->set("app_config", log_event_store(app_config_).as_slice().str());
}
G()->get_option_manager()->update_premium_options();
for (auto &promise : promises) {
promise.set_value(convert_json_value_object(app_config_.config_));
}
@ -1305,7 +1307,7 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
set_timeout_at(expire_time_.at());
LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test";
Global &options = *G();
OptionManager &options = *G()->get_option_manager();
// Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator.
DcOptions dc_options(config->dc_options_);
@ -2068,60 +2070,6 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
options.set_option_integer("chat_folder_new_chats_update_period", dialog_filter_update_period);
}
bool is_premium = options.get_option_boolean("is_premium");
if (is_premium) {
options.set_option_integer("chat_folder_count_max", options.get_option_integer("dialog_filters_limit_premium", 20));
options.set_option_integer("chat_folder_chosen_chat_count_max",
options.get_option_integer("dialog_filters_chats_limit_premium", 200));
options.set_option_integer("active_story_count_max",
options.get_option_integer("story_expiring_limit_premium", 100));
options.set_option_integer("weekly_sent_story_count_max",
options.get_option_integer("stories_sent_weekly_limit_premium", 700));
options.set_option_integer("monthly_sent_story_count_max",
options.get_option_integer("stories_sent_monthly_limit_premium", 3000));
options.set_option_integer("story_caption_length_max",
options.get_option_integer("story_caption_length_limit_premium", 2048));
options.set_option_integer("story_suggested_reaction_area_count_max",
options.get_option_integer("stories_suggested_reactions_limit_premium", 5));
options.set_option_integer("bio_length_max", options.get_option_integer("about_length_limit_premium", 140));
options.set_option_integer("saved_animations_limit", options.get_option_integer("saved_gifs_limit_premium", 400));
options.set_option_integer("favorite_stickers_limit",
options.get_option_integer("stickers_faved_limit_premium", 10));
options.set_option_integer("pinned_chat_count_max",
options.get_option_integer("dialogs_pinned_limit_premium", 200));
options.set_option_integer("pinned_archived_chat_count_max",
options.get_option_integer("dialogs_folder_pinned_limit_premium", 200));
options.set_option_integer("chat_folder_invite_link_count_max",
options.get_option_integer("chatlist_invites_limit_premium", 20));
options.set_option_integer("added_shareable_chat_folder_count_max",
options.get_option_integer("chatlists_joined_limit_premium", 20));
} else {
options.set_option_integer("chat_folder_count_max", options.get_option_integer("dialog_filters_limit_default", 10));
options.set_option_integer("chat_folder_chosen_chat_count_max",
options.get_option_integer("dialog_filters_chats_limit_default", 100));
options.set_option_integer("active_story_count_max", options.get_option_integer("story_expiring_limit_default", 3));
options.set_option_integer("weekly_sent_story_count_max",
options.get_option_integer("stories_sent_weekly_limit_default", 7));
options.set_option_integer("monthly_sent_story_count_max",
options.get_option_integer("stories_sent_monthly_limit_default", 30));
options.set_option_integer("story_caption_length_max",
options.get_option_integer("story_caption_length_limit_default", 200));
options.set_option_integer("story_suggested_reaction_area_count_max",
options.get_option_integer("stories_suggested_reactions_limit_default", 1));
options.set_option_integer("bio_length_max", options.get_option_integer("about_length_limit_default", 70));
options.set_option_integer("saved_animations_limit", options.get_option_integer("saved_gifs_limit_default", 200));
options.set_option_integer("favorite_stickers_limit",
options.get_option_integer("stickers_faved_limit_default", 5));
options.set_option_integer("pinned_chat_count_max",
options.get_option_integer("dialogs_pinned_limit_default", 100));
options.set_option_integer("pinned_archived_chat_count_max",
options.get_option_integer("dialogs_folder_pinned_limit_default", 100));
options.set_option_integer("chat_folder_invite_link_count_max",
options.get_option_integer("chatlist_invites_limit_default", 3));
options.set_option_integer("added_shareable_chat_folder_count_max",
options.get_option_integer("chatlists_joined_limit_default", 2));
}
if (!is_premium_available) {
premium_bot_username.clear(); // just in case
premium_invoice_slug.clear(); // just in case

View File

@ -331,6 +331,7 @@ class Global final : public ActorContext {
void set_option_manager(OptionManager *option_manager) {
option_manager_ = option_manager;
}
OptionManager *get_option_manager();
ActorId<PasswordManager> password_manager() const {
return password_manager_;
@ -610,8 +611,6 @@ class Global final : public ActorContext {
const OptionManager *get_option_manager() const;
OptionManager *get_option_manager();
void do_save_server_time_difference();
void do_close(Promise<> on_finish, bool destroy_flag);

View File

@ -21,6 +21,7 @@
#include "td/telegram/net/MtprotoHeader.h"
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/NotificationManager.h"
#include "td/telegram/Premium.h"
#include "td/telegram/ReactionType.h"
#include "td/telegram/StateManager.h"
#include "td/telegram/StickersManager.h"
@ -153,6 +154,8 @@ OptionManager::OptionManager(Td *td)
set_option_integer("chat_boost_level_max", G()->is_test_dc() ? 10 : 100);
}
update_premium_options();
set_option_empty("archive_and_mute_new_chats_from_unknown_users");
set_option_empty("chat_filter_count_max");
set_option_empty("chat_filter_chosen_chat_count_max");
@ -163,6 +166,49 @@ OptionManager::OptionManager(Td *td)
OptionManager::~OptionManager() = default;
void OptionManager::update_premium_options() {
bool is_premium = get_option_boolean("is_premium");
if (is_premium) {
set_option_integer("saved_animations_limit", get_option_integer("saved_gifs_limit_premium", 400));
set_option_integer("favorite_stickers_limit", get_option_integer("stickers_faved_limit_premium", 10));
set_option_integer("chat_folder_count_max", get_option_integer("dialog_filters_limit_premium", 20));
set_option_integer("chat_folder_chosen_chat_count_max",
get_option_integer("dialog_filters_chats_limit_premium", 200));
set_option_integer("pinned_chat_count_max", get_option_integer("dialogs_pinned_limit_premium", 200));
set_option_integer("pinned_archived_chat_count_max",
get_option_integer("dialogs_folder_pinned_limit_premium", 200));
set_option_integer("bio_length_max", get_option_integer("about_length_limit_premium", 140));
set_option_integer("chat_folder_invite_link_count_max", get_option_integer("chatlist_invites_limit_premium", 20));
set_option_integer("added_shareable_chat_folder_count_max",
get_option_integer("chatlists_joined_limit_premium", 20));
set_option_integer("active_story_count_max", get_option_integer("story_expiring_limit_premium", 100));
set_option_integer("story_caption_length_max", get_option_integer("story_caption_length_limit_premium", 2048));
set_option_integer("weekly_sent_story_count_max", get_option_integer("stories_sent_weekly_limit_premium", 700));
set_option_integer("monthly_sent_story_count_max", get_option_integer("stories_sent_monthly_limit_premium", 3000));
set_option_integer("story_suggested_reaction_area_count_max",
get_option_integer("stories_suggested_reactions_limit_premium", 5));
} else {
set_option_integer("saved_animations_limit", get_option_integer("saved_gifs_limit_default", 200));
set_option_integer("favorite_stickers_limit", get_option_integer("stickers_faved_limit_default", 5));
set_option_integer("chat_folder_count_max", get_option_integer("dialog_filters_limit_default", 10));
set_option_integer("chat_folder_chosen_chat_count_max",
get_option_integer("dialog_filters_chats_limit_default", 100));
set_option_integer("pinned_chat_count_max", get_option_integer("dialogs_pinned_limit_default", 100));
set_option_integer("pinned_archived_chat_count_max",
get_option_integer("dialogs_folder_pinned_limit_default", 100));
set_option_integer("bio_length_max", get_option_integer("about_length_limit_default", 70));
set_option_integer("chat_folder_invite_link_count_max", get_option_integer("chatlist_invites_limit_default", 3));
set_option_integer("added_shareable_chat_folder_count_max",
get_option_integer("chatlists_joined_limit_default", 2));
set_option_integer("active_story_count_max", get_option_integer("story_expiring_limit_default", 3));
set_option_integer("story_caption_length_max", get_option_integer("story_caption_length_limit_default", 200));
set_option_integer("weekly_sent_story_count_max", get_option_integer("stories_sent_weekly_limit_default", 7));
set_option_integer("monthly_sent_story_count_max", get_option_integer("stories_sent_monthly_limit_default", 30));
set_option_integer("story_suggested_reaction_area_count_max",
get_option_integer("stories_suggested_reactions_limit_default", 1));
}
}
void OptionManager::on_td_inited() {
is_td_inited_ = true;

View File

@ -31,6 +31,8 @@ class OptionManager {
OptionManager &operator=(OptionManager &&) = delete;
~OptionManager();
void update_premium_options();
void on_td_inited();
void set_option_boolean(Slice name, bool value);