Simplify username caching.
This commit is contained in:
parent
102c40cc3b
commit
62403aac3c
@ -11635,15 +11635,6 @@ void ContactsManager::on_get_channel_full_failed(ChannelId channel_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContactsManager::is_update_about_username_change_received(UserId user_id) const {
|
|
||||||
const User *u = get_user(user_id);
|
|
||||||
if (u != nullptr) {
|
|
||||||
return u->is_contact;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContactsManager::on_update_user_name(UserId user_id, string &&first_name, string &&last_name, string &&username) {
|
void ContactsManager::on_update_user_name(UserId user_id, string &&first_name, string &&last_name, string &&username) {
|
||||||
if (!user_id.is_valid()) {
|
if (!user_id.is_valid()) {
|
||||||
LOG(ERROR) << "Receive invalid " << user_id;
|
LOG(ERROR) << "Receive invalid " << user_id;
|
||||||
|
@ -127,8 +127,6 @@ class ContactsManager final : public Actor {
|
|||||||
|
|
||||||
string get_dialog_about(DialogId dialog_id);
|
string get_dialog_about(DialogId dialog_id);
|
||||||
|
|
||||||
bool is_update_about_username_change_received(UserId user_id) const;
|
|
||||||
|
|
||||||
void for_each_secret_chat_with_user(UserId user_id, const std::function<void(SecretChatId)> &f);
|
void for_each_secret_chat_with_user(UserId user_id, const std::function<void(SecretChatId)> &f);
|
||||||
|
|
||||||
string get_user_username(UserId user_id) const;
|
string get_user_username(UserId user_id) const;
|
||||||
|
@ -33462,23 +33462,6 @@ void MessagesManager::on_get_dialog_query_finished(DialogId dialog_id, Status &&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessagesManager::is_update_about_username_change_received(DialogId dialog_id) const {
|
|
||||||
switch (dialog_id.get_type()) {
|
|
||||||
case DialogType::User:
|
|
||||||
return td_->contacts_manager_->is_update_about_username_change_received(dialog_id.get_user_id());
|
|
||||||
case DialogType::Chat:
|
|
||||||
return true;
|
|
||||||
case DialogType::Channel:
|
|
||||||
return td_->contacts_manager_->get_channel_status(dialog_id.get_channel_id()).is_member();
|
|
||||||
case DialogType::SecretChat:
|
|
||||||
return true;
|
|
||||||
case DialogType::None:
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessagesManager::on_dialog_username_updated(DialogId dialog_id, const string &old_username,
|
void MessagesManager::on_dialog_username_updated(DialogId dialog_id, const string &old_username,
|
||||||
const string &new_username) {
|
const string &new_username) {
|
||||||
CHECK(dialog_id.is_valid());
|
CHECK(dialog_id.is_valid());
|
||||||
@ -33495,11 +33478,9 @@ void MessagesManager::on_dialog_username_updated(DialogId dialog_id, const strin
|
|||||||
inaccessible_resolved_usernames_.erase(clean_username(old_username));
|
inaccessible_resolved_usernames_.erase(clean_username(old_username));
|
||||||
}
|
}
|
||||||
if (!new_username.empty()) {
|
if (!new_username.empty()) {
|
||||||
auto cache_time = is_update_about_username_change_received(dialog_id) ? USERNAME_CACHE_EXPIRE_TIME
|
|
||||||
: USERNAME_CACHE_EXPIRE_TIME_SHORT;
|
|
||||||
auto cleaned_username = clean_username(new_username);
|
auto cleaned_username = clean_username(new_username);
|
||||||
if (!cleaned_username.empty()) {
|
if (!cleaned_username.empty()) {
|
||||||
resolved_usernames_[cleaned_username] = ResolvedUsername{dialog_id, Time::now() + cache_time};
|
resolved_usernames_[cleaned_username] = ResolvedUsername{dialog_id, Time::now() + USERNAME_CACHE_EXPIRE_TIME};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -851,8 +851,6 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
bool is_old_channel_update(DialogId dialog_id, int32 new_pts);
|
bool is_old_channel_update(DialogId dialog_id, int32 new_pts);
|
||||||
|
|
||||||
bool is_update_about_username_change_received(DialogId dialog_id) const;
|
|
||||||
|
|
||||||
void on_dialog_bots_updated(DialogId dialog_id, vector<UserId> bot_user_ids, bool from_database);
|
void on_dialog_bots_updated(DialogId dialog_id, vector<UserId> bot_user_ids, bool from_database);
|
||||||
|
|
||||||
void on_dialog_photo_updated(DialogId dialog_id);
|
void on_dialog_photo_updated(DialogId dialog_id);
|
||||||
@ -1825,8 +1823,7 @@ class MessagesManager final : public Actor {
|
|||||||
static constexpr int32 LIVE_LOCATION_VIEW_PERIOD = 60; // seconds, server-side limit
|
static constexpr int32 LIVE_LOCATION_VIEW_PERIOD = 60; // seconds, server-side limit
|
||||||
static constexpr int32 UPDATE_VIEWED_MESSAGES_PERIOD = 15; // seconds
|
static constexpr int32 UPDATE_VIEWED_MESSAGES_PERIOD = 15; // seconds
|
||||||
|
|
||||||
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME = 3 * 86400;
|
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME = 86400;
|
||||||
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME_SHORT = 900;
|
|
||||||
static constexpr int32 AUTH_NOTIFICATION_ID_CACHE_TIME = 7 * 86400;
|
static constexpr int32 AUTH_NOTIFICATION_ID_CACHE_TIME = 7 * 86400;
|
||||||
static constexpr size_t MAX_SAVED_AUTH_NOTIFICATION_IDS = 100;
|
static constexpr size_t MAX_SAVED_AUTH_NOTIFICATION_IDS = 100;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user