From a3ac41e2835965c4bc58a4995b30d35447921d3e Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 19 Jan 2024 14:35:37 +0300 Subject: [PATCH] Add user.restricts_new_chats. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/ContactsManager.cpp | 16 +++++++++++----- td/telegram/ContactsManager.h | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0eaacd23d..306898ba1 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -804,11 +804,12 @@ usernames active_usernames:vector disabled_usernames:vector edit //@is_fake True, if many users reported this user as a fake account //@has_active_stories True, if the user has non-expired stories available to the current user //@has_unread_active_stories True, if the user has unread non-expired stories available to the current user +//@restricts_new_chats True, if the user may restrict new chats with non-contacts. Use canSendMessageToUser to check whether the current user can message the user or try to create a chat with them //@have_access If false, the user is inaccessible, and the only information known about the user is inside this class. Identifier of the user can't be passed to any method //@type Type of the user //@language_code IETF language tag of the user's language; only available to bots //@added_to_attachment_menu True, if the user added the current bot to attachment menu; only available to bots -user id:int53 first_name:string last_name:string usernames:usernames phone_number:string status:UserStatus profile_photo:profilePhoto accent_color_id:int32 background_custom_emoji_id:int64 profile_accent_color_id:int32 profile_background_custom_emoji_id:int64 emoji_status:emojiStatus is_contact:Bool is_mutual_contact:Bool is_close_friend:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool has_active_stories:Bool has_unread_active_stories:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User; +user id:int53 first_name:string last_name:string usernames:usernames phone_number:string status:UserStatus profile_photo:profilePhoto accent_color_id:int32 background_custom_emoji_id:int64 profile_accent_color_id:int32 profile_background_custom_emoji_id:int64 emoji_status:emojiStatus is_contact:Bool is_mutual_contact:Bool is_close_friend:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool has_active_stories:Bool has_unread_active_stories:Bool restricts_new_chats:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User; //@description Contains information about a bot diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 6c3c8a0df..d06f18bd9 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3306,6 +3306,7 @@ void ContactsManager::User::store(StorerT &storer) const { STORE_FLAG(has_background_custom_emoji_id); STORE_FLAG(has_profile_accent_color_id); STORE_FLAG(has_profile_background_custom_emoji_id); + STORE_FLAG(contact_require_premium); END_STORE_FLAGS(); } store(first_name, storer); @@ -3431,6 +3432,7 @@ void ContactsManager::User::parse(ParserT &parser) { PARSE_FLAG(has_background_custom_emoji_id); PARSE_FLAG(has_profile_accent_color_id); PARSE_FLAG(has_profile_background_custom_emoji_id); + PARSE_FLAG(contact_require_premium); END_PARSE_FLAGS(); } parse(first_name, parser); @@ -9102,6 +9104,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, bool stories_available = user->stories_max_id_ > 0; bool stories_unavailable = user->stories_unavailable_; bool stories_hidden = user->stories_hidden_; + bool contact_require_premium = user->contact_require_premium_; LOG_IF(ERROR, !can_join_groups && !is_bot) << "Receive not bot " << user_id << " which can't join groups from " << source; @@ -9140,7 +9143,8 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, can_join_groups != u->can_join_groups || can_read_all_group_messages != u->can_read_all_group_messages || is_scam != u->is_scam || is_fake != u->is_fake || is_inline_bot != u->is_inline_bot || inline_query_placeholder != u->inline_query_placeholder || need_location_bot != u->need_location_bot || - can_be_added_to_attach_menu != u->can_be_added_to_attach_menu) { + can_be_added_to_attach_menu != u->can_be_added_to_attach_menu || + contact_require_premium != u->contact_require_premium) { if (is_bot != u->is_bot) { LOG_IF(ERROR, !is_deleted && !u->is_deleted && u->is_received) << "User.is_bot has changed for " << user_id << "/" << u->usernames << " from " << source << " from " @@ -9158,6 +9162,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, u->inline_query_placeholder = std::move(inline_query_placeholder); u->need_location_bot = need_location_bot; u->can_be_added_to_attach_menu = can_be_added_to_attach_menu; + u->contact_require_premium = contact_require_premium; LOG(DEBUG) << "Info has changed for " << user_id; u->is_changed = true; @@ -17663,8 +17668,8 @@ td_api::object_ptr ContactsManager::get_update_unknown_user_ return td_api::make_object(td_api::make_object( user_id.get(), "", "", nullptr, "", td_api::make_object(), nullptr, td_->theme_manager_->get_accent_color_id_object(AccentColorId(user_id)), 0, -1, 0, nullptr, false, false, false, - false, false, false, "", false, false, false, false, have_access, td_api::make_object(), - "", false)); + false, false, false, "", false, false, false, false, false, have_access, + td_api::make_object(), "", false)); } int64 ContactsManager::get_user_id_object(UserId user_id, const char *source) const { @@ -17698,6 +17703,7 @@ tl_object_ptr ContactsManager::get_user_object(UserId user_id, con auto emoji_status = u->last_sent_emoji_status.get_emoji_status_object(); auto have_access = user_id == get_my_id() || have_input_peer_user(u, user_id, AccessRights::Know); auto accent_color_id = u->accent_color_id.is_valid() ? u->accent_color_id : AccentColorId(user_id); + auto restricts_new_chats = u->contact_require_premium && !u->is_mutual_contact; return td_api::make_object( user_id.get(), u->first_name, u->last_name, u->usernames.get_usernames_object(), u->phone_number, get_user_status_object(user_id, u, G()->unix_time()), @@ -17708,8 +17714,8 @@ tl_object_ptr ContactsManager::get_user_object(UserId user_id, con u->profile_background_custom_emoji_id.get(), std::move(emoji_status), u->is_contact, u->is_mutual_contact, u->is_close_friend, u->is_verified, u->is_premium, u->is_support, get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake, - u->max_active_story_id.is_valid(), get_user_has_unread_stories(u), have_access, std::move(type), u->language_code, - u->attach_menu_enabled); + u->max_active_story_id.is_valid(), get_user_has_unread_stories(u), restricts_new_chats, have_access, + std::move(type), u->language_code, u->attach_menu_enabled); } vector ContactsManager::get_user_ids_object(const vector &user_ids, const char *source) const { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index ce80ab5bb..7a3a6b1d1 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -761,6 +761,7 @@ class ContactsManager final : public Actor { bool can_be_added_to_attach_menu = false; bool attach_menu_enabled = false; bool stories_hidden = false; + bool contact_require_premium = false; bool is_photo_inited = false;