Drop UserFull cache when phone number privacy is changed.

GitOrigin-RevId: 4ff14b72fa4b903c9358a1a10023e7b5f3775ff8
This commit is contained in:
levlam 2020-05-01 01:21:02 +03:00
parent bbdad2c9e2
commit 8bbc32e21c
3 changed files with 34 additions and 13 deletions

View File

@ -6823,6 +6823,14 @@ void ContactsManager::on_update_online_status_privacy() {
td_->create_handler<GetContactsStatusesQuery>()->send();
}
void ContactsManager::on_update_phone_number_privacy() {
// all UserFull.need_phone_number_privacy_exception can be outdated now,
// so mark all of them as expired
for (auto &it : users_full_) {
it.second->expires_at = 0.0;
}
}
UserId ContactsManager::get_user_id(const tl_object_ptr<telegram_api::User> &user) {
CHECK(user != nullptr);
switch (user->get_id()) {

View File

@ -256,6 +256,8 @@ class ContactsManager : public Actor {
void on_update_online_status_privacy();
void on_update_phone_number_privacy();
void on_channel_unban_timeout(ChannelId channel_id);
void check_dialog_username(DialogId dialog_id, const string &username, Promise<CheckDialogUsernameResult> &&promise);

View File

@ -519,23 +519,34 @@ void PrivacyManager::do_update_privacy(UserPrivacySetting user_privacy_setting,
info.is_synchronized = true;
if (!(info.rules == privacy_rules)) {
if ((from_update || was_synchronized) && user_privacy_setting.type() == UserPrivacySetting::Type::UserStatus &&
!G()->close_flag()) {
send_closure_later(G()->contacts_manager(), &ContactsManager::on_update_online_status_privacy);
if ((from_update || was_synchronized) && !G()->close_flag()) {
switch (user_privacy_setting.type()) {
case UserPrivacySetting::Type::UserStatus: {
send_closure_later(G()->contacts_manager(), &ContactsManager::on_update_online_status_privacy);
auto old_restricted = info.rules.get_restricted_user_ids();
auto new_restricted = privacy_rules.get_restricted_user_ids();
if (old_restricted != new_restricted) {
// if a user was unrestricted, it is not received from the server anymore
// we need to reget their online status manually
std::vector<int32> unrestricted;
std::set_difference(old_restricted.begin(), old_restricted.end(), new_restricted.begin(), new_restricted.end(),
std::back_inserter(unrestricted));
for (auto &user_id : unrestricted) {
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_user, UserId(user_id), Promise<Unit>());
auto old_restricted = info.rules.get_restricted_user_ids();
auto new_restricted = privacy_rules.get_restricted_user_ids();
if (old_restricted != new_restricted) {
// if a user was unrestricted, it is not received from the server anymore
// we need to reget their online status manually
std::vector<int32> unrestricted;
std::set_difference(old_restricted.begin(), old_restricted.end(), new_restricted.begin(),
new_restricted.end(), std::back_inserter(unrestricted));
for (auto &user_id : unrestricted) {
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_user, UserId(user_id),
Promise<Unit>());
}
}
break;
}
case UserPrivacySetting::Type::UserPhoneNumber:
send_closure_later(G()->contacts_manager(), &ContactsManager::on_update_phone_number_privacy);
break;
default:
break;
}
}
info.rules = std::move(privacy_rules);
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateUserPrivacySettingRules>(user_privacy_setting.as_td_api(),