From 42ab42c83a29c782a3ad39781551d220076f03c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 30 May 2022 03:23:21 +0300 Subject: [PATCH] Add bio_length_max option. --- td/generate/scheme/td_api.tl | 2 +- td/telegram/ConfigManager.cpp | 4 ++++ td/telegram/ContactsManager.cpp | 3 ++- td/telegram/ContactsManager.h | 1 - td/telegram/OptionManager.cpp | 3 +++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4a2fe7e78..bb50d226d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5911,7 +5911,7 @@ deleteProfilePhoto profile_photo_id:int64 = Ok; //@description Changes the first and last name of the current user @first_name The new value of the first name for the current user; 1-64 characters @last_name The new value of the optional last name for the current user; 0-64 characters setName first_name:string last_name:string = Ok; -//@description Changes the bio of the current user @bio The new value of the user bio; 0-70 characters without line feeds +//@description Changes the bio of the current user @bio The new value of the user bio; 0-GetOption("bio_length_max") characters without line feeds setBio bio:string = Ok; //@description Changes the username of the current user @username The new value of the username. Use an empty string to remove the username diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 942fe5a46..48dcf7f7f 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1875,6 +1875,10 @@ void ConfigManager::process_app_config(tl_object_ptr &c shared_config.set_option_integer("chat_filter_chosen_chat_count_max", static_cast(chat_filter_chosen_chat_count_max)); + auto bio_length_max = shared_config.get_option_integer( + is_premium ? Slice("about_length_limit_premium") : Slice("about_length_limit_default"), is_premium ? 140 : 70); + shared_config.set_option_integer("bio_length_max", bio_length_max); + shared_config.set_option_string("premium_features", implode(premium_features, ',')); if (premium_bot_username.empty()) { shared_config.set_option_empty("premium_bot_username"); diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 43d978f27..e10a29697 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6456,7 +6456,8 @@ void ContactsManager::set_name(const string &first_name, const string &last_name } void ContactsManager::set_bio(const string &bio, Promise &&promise) { - auto new_bio = strip_empty_characters(bio, MAX_BIO_LENGTH); + auto max_bio_length = static_cast(G()->shared_config().get_option_integer("bio_length_max")); + auto new_bio = strip_empty_characters(bio, max_bio_length); for (auto &c : new_bio) { if (c == '\n') { c = ' '; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 3d9dbc64a..fe881ba48 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1024,7 +1024,6 @@ class ContactsManager final : public Actor { static constexpr int32 MAX_GET_PROFILE_PHOTOS = 100; // server side limit static constexpr size_t MAX_NAME_LENGTH = 64; // server side limit for first/last name static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat/channel description - static constexpr size_t MAX_BIO_LENGTH = 70; // server side limit static constexpr size_t MAX_INVITE_LINK_TITLE_LENGTH = 32; // server side limit static constexpr int32 MAX_GET_CHANNEL_PARTICIPANTS = 200; // server side limit diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index f305bb384..eb06960e8 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -93,6 +93,9 @@ OptionManager::OptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(st if (!G()->shared_config().have_option("message_caption_length_max")) { G()->shared_config().set_option_integer("message_caption_length_max", 1024); } + if (!G()->shared_config().have_option("bio_length_max")) { + G()->shared_config().set_option_integer("bio_length_max", 70); + } if (!G()->shared_config().have_option("suggested_video_note_length")) { G()->shared_config().set_option_integer("suggested_video_note_length", 384); }