Add need_phone_number_privacy_exception.

GitOrigin-RevId: b1d6237900577a50dcc105d72962cebe62ee70ca
This commit is contained in:
levlam 2019-10-11 00:18:34 +03:00
parent 1b147a8142
commit 91bdd50884
5 changed files with 68 additions and 12 deletions

View File

@ -299,9 +299,11 @@ botInfo description:string commands:vector<botCommand> = BotInfo;
//@have_access If false, the user is inaccessible, and the only information known about the user is inside this class. It can't be passed to any method except GetUser @type Type of the user @language_code IETF language tag of the user's language; only available to bots
user id:int32 first_name:string last_name:string username:string phone_number:string status:UserStatus profile_photo:profilePhoto is_contact:Bool is_mutual_contact:Bool is_verified:Bool is_support:Bool restriction_reason:string is_scam:Bool have_access:Bool type:UserType language_code:string = User;
//@description Contains full information about a user (except the full list of profile photos) @is_blocked True, if the user is blacklisted by the current user @can_be_called True, if the user can be called @has_private_calls True, if the user can't be called due to their privacy settings
//@description Contains full information about a user (except the full list of profile photos) @is_blocked True, if the user is blacklisted by the current user
//@can_be_called True, if the user can be called @has_private_calls True, if the user can't be called due to their privacy settings
//@need_phone_number_privacy_exception True, if the current user needs to explicitly allow to share his phone number with the user when the method addContact is used
//@bio A short user bio @share_text For bots, the text that is included with the link when users share the bot @group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user @bot_info If the user is a bot, information about the bot; may be null
userFullInfo is_blocked:Bool can_be_called:Bool has_private_calls:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo;
userFullInfo is_blocked:Bool can_be_called:Bool has_private_calls:Bool need_phone_number_privacy_exception:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo;
//@description Contains full information about a user profile photo @id Unique user profile photo identifier @added_date Point in time (Unix timestamp) when the photo has been added @sizes Available variants of the user photo, in different sizes
userProfilePhoto id:int64 added_date:int32 sizes:vector<photoSize> = UserProfilePhoto;
@ -3568,7 +3570,7 @@ getBlockedUsers offset:int32 limit:int32 = Users;
//@description Adds a user to the contacts list or edits an existing contact by their user_id @contact The contact to add or edit; phone number can be empty and needs to be specified only if known, vCard is ignored
//@share_phone_number True, if the user needs to be allowed to see current user's phone number. A corresponding rule to userPrivacySettingShowPhoneNumber will be added if needed
//@share_phone_number True, if the new contact needs to be allowed to see current user's phone number. A corresponding rule to userPrivacySettingShowPhoneNumber will be added if needed. Use the field UserFullInfo.need_phone_number_privacy_exception to check whether the current user needs to be asked to share his phone number
addContact contact:contact share_phone_number:Bool = Ok;
//@description Adds new contacts or edits existing contacts by their phone numbers; contacts' user identifiers are ignored @contacts The list of contacts to import or edit; contacts' vCard are ignored and are not imported

Binary file not shown.

View File

@ -2695,6 +2695,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
STORE_FLAG(can_be_called);
STORE_FLAG(has_private_calls);
STORE_FLAG(can_pin_messages);
STORE_FLAG(need_phone_number_privacy_exception);
END_STORE_FLAGS();
if (has_bot_info) {
store(bot_info, storer);
@ -2719,6 +2720,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
PARSE_FLAG(can_be_called);
PARSE_FLAG(has_private_calls);
PARSE_FLAG(can_pin_messages);
PARSE_FLAG(need_phone_number_privacy_exception);
END_PARSE_FLAGS();
if (has_bot_info) {
parse(bot_info, parser);
@ -6766,6 +6768,10 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val
dependencies.user_ids.insert(user_id);
td_->messages_manager_->resolve_dependencies_force(dependencies);
if (user_full->need_phone_number_privacy_exception && is_user_contact(user_id)) {
user_full->need_phone_number_privacy_exception = false;
}
update_user_full(user_full, user_id, true);
}
@ -6941,6 +6947,15 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
if (u->is_name_changed || u->is_username_changed || u->is_is_contact_changed) {
update_contacts_hints(u, user_id, from_database);
}
if (u->is_is_contact_changed) {
if (u->is_contact) {
auto user_full = get_user_full(user_id);
if (user_full != nullptr && user_full->need_phone_number_privacy_exception) {
on_update_user_full_need_phone_number_privacy_exception(user_full, user_id, false);
update_user_full(user_full, user_id);
}
}
}
if (u->is_name_changed) {
td_->messages_manager_->on_dialog_title_updated(DialogId(user_id));
auto it = secret_chats_with_user_.find(user_id);
@ -7321,8 +7336,6 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
td_->messages_manager_->on_update_dialog_notify_settings(DialogId(user_id), std::move(user_full->notify_settings_),
"on_get_user_full");
td_->messages_manager_->on_get_peer_settings(DialogId(user_id), std::move(user_full->settings_));
{
MessageId pinned_message_id;
if ((user_full->flags_ & USER_FULL_FLAG_HAS_PINNED_MESSAGE) != 0) {
@ -7347,6 +7360,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
on_update_user_full_is_blocked(user, user_id, (user_full->flags_ & USER_FULL_FLAG_IS_BLOCKED) != 0);
on_update_user_full_common_chat_count(user, user_id, user_full->common_chats_count_);
on_update_user_full_need_phone_number_privacy_exception(
user, user_id, (user_full->settings_->flags_ & telegram_api::peerSettings::NEED_CONTACTS_EXCEPTION_MASK) != 0);
bool can_pin_messages = user_full->can_pin_message_;
if (user->can_pin_messages != can_pin_messages) {
@ -7375,6 +7390,9 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
on_update_user_full_bot_info(user, user_id, u->bot_info_version, std::move(user_full->bot_info_));
}
update_user_full(user, user_id);
// update peer settings after UserFull is created and updated to not update twice need_phone_number_privacy_exception
td_->messages_manager_->on_get_peer_settings(DialogId(user_id), std::move(user_full->settings_));
}
void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 limit, int32 total_count,
@ -8054,6 +8072,32 @@ void ContactsManager::on_update_user_full_common_chat_count(UserFull *user_full,
}
}
void ContactsManager::on_update_user_need_phone_number_privacy_exception(UserId user_id,
bool need_phone_number_privacy_exception) {
LOG(INFO) << "Receive " << need_phone_number_privacy_exception << " need phone number privacy exception with "
<< user_id;
if (!user_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << user_id;
return;
}
UserFull *user_full = get_user_full_force(user_id);
if (user_full == nullptr) {
return;
}
on_update_user_full_need_phone_number_privacy_exception(user_full, user_id, need_phone_number_privacy_exception);
update_user_full(user_full, user_id);
}
void ContactsManager::on_update_user_full_need_phone_number_privacy_exception(
UserFull *user_full, UserId user_id, bool need_phone_number_privacy_exception) {
CHECK(user_full != nullptr);
if (user_full->is_inited && user_full->need_phone_number_privacy_exception != need_phone_number_privacy_exception) {
user_full->need_phone_number_privacy_exception = need_phone_number_privacy_exception;
user_full->is_changed = true;
}
}
void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise<Unit> promise) {
UserId my_id = get_my_id();
@ -8087,6 +8131,7 @@ void ContactsManager::drop_user_full(UserId user_id) {
user_full->is_blocked = false;
user_full->can_be_called = false;
user_full->has_private_calls = false;
user_full->need_phone_number_privacy_exception = false;
user_full->about = string();
user_full->common_chat_count = 0;
user_full->bot_info = nullptr;
@ -11334,8 +11379,9 @@ tl_object_ptr<td_api::userFullInfo> ContactsManager::get_user_full_info_object(U
const UserFull *user_full) const {
CHECK(user_full != nullptr);
bool is_bot = is_user_bot(user_id);
return make_tl_object<td_api::userFullInfo>(user_full->is_blocked, user_full->can_be_called,
user_full->has_private_calls, is_bot ? string() : user_full->about,
return make_tl_object<td_api::userFullInfo>(
user_full->is_blocked, user_full->can_be_called, user_full->has_private_calls,
user_full->need_phone_number_privacy_exception, is_bot ? string() : user_full->about,
is_bot ? user_full->about : string(), user_full->common_chat_count,
get_bot_info_object(user_full->bot_info.get()));
}

View File

@ -160,6 +160,7 @@ class ContactsManager : public Actor {
void on_update_user_local_was_online(UserId user_id, int32 local_was_online);
void on_update_user_blocked(UserId user_id, bool is_blocked);
void on_update_user_common_chat_count(UserId user_id, int32 common_chat_count);
void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception);
void on_delete_profile_photo(int64 profile_photo_id, Promise<Unit> promise);
@ -577,6 +578,7 @@ class ContactsManager : public Actor {
bool can_be_called = false;
bool has_private_calls = false;
bool can_pin_messages = false;
bool need_phone_number_privacy_exception = false;
bool is_common_chat_count_changed = true;
bool is_changed = true;
@ -953,6 +955,8 @@ class ContactsManager : public Actor {
void on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked);
void on_update_user_full_common_chat_count(UserFull *user_full, UserId user_id, int32 common_chat_count);
void on_update_user_full_need_phone_number_privacy_exception(UserFull *user_full, UserId user_id,
bool need_phone_number_privacy_exception);
bool on_update_user_full_bot_info(UserFull *user_full, UserId user_id, int32 bot_info_version,
tl_object_ptr<telegram_api::botInfo> &&bot_info);
void drop_user_full(UserId user_id);

View File

@ -6630,9 +6630,10 @@ void MessagesManager::on_get_peer_settings(DialogId dialog_id,
tl_object_ptr<telegram_api::peerSettings> &&peer_settings) {
CHECK(peer_settings != nullptr);
if (dialog_id.get_type() == DialogType::User) {
// auto need_phone_number_privacy_exception =
// (peer_settings->flags_ & telegram_api::peerSettings::NEED_CONTACTS_EXCEPTION_MASK) != 0;
// TODO use need_phone_number_privacy_exception
auto need_phone_number_privacy_exception =
(peer_settings->flags_ & telegram_api::peerSettings::NEED_CONTACTS_EXCEPTION_MASK) != 0;
td_->contacts_manager_->on_update_user_need_phone_number_privacy_exception(dialog_id.get_user_id(),
need_phone_number_privacy_exception);
}
Dialog *d = get_dialog_force(dialog_id);
@ -25718,6 +25719,9 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
loaded_dialogs_.erase(dialog_id);
Dialog *dialog = dialog_it->second.get();
fix_dialog_action_bar(dialog);
send_update_new_chat(dialog);
fix_new_dialog(dialog, std::move(last_database_message), last_database_message_id, order, last_clear_history_date,