Update username cache with usernames loaded from database.
This commit is contained in:
parent
02ef8b914d
commit
999aaaf610
@ -12038,6 +12038,9 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
if (u->is_deleted) {
|
||||
td_->inline_queries_manager_->remove_recent_inline_bot(user_id, Promise<>());
|
||||
}
|
||||
if (from_binlog || from_database) {
|
||||
td_->messages_manager_->on_dialog_usernames_received(DialogId(user_id), u->usernames, true);
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Update " << user_id << ": need_save_to_database = " << u->need_save_to_database
|
||||
<< ", is_changed = " << u->is_changed << ", is_status_changed = " << u->is_status_changed
|
||||
@ -12260,6 +12263,10 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
}
|
||||
}
|
||||
|
||||
if (from_binlog || from_database) {
|
||||
td_->messages_manager_->on_dialog_usernames_received(DialogId(channel_id), c->usernames, true);
|
||||
}
|
||||
|
||||
if (!is_channel_public(c) && !c->has_linked_channel) {
|
||||
send_closure_later(G()->messages_manager(), &MessagesManager::on_update_dialog_default_send_message_as_dialog_id,
|
||||
DialogId(channel_id), DialogId(), false);
|
||||
@ -13316,8 +13323,8 @@ void ContactsManager::on_update_user_name(User *u, UserId user_id, string &&firs
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_user_usernames(User *u, UserId user_id, Usernames &&usernames) {
|
||||
td_->messages_manager_->on_dialog_usernames_updated(DialogId(user_id), u->usernames, usernames);
|
||||
if (u->usernames != usernames) {
|
||||
td_->messages_manager_->on_dialog_usernames_updated(DialogId(user_id), u->usernames, usernames);
|
||||
if (u->can_be_edited_bot && u->usernames.get_editable_username() != usernames.get_editable_username()) {
|
||||
u->is_full_info_changed = true;
|
||||
}
|
||||
@ -13325,6 +13332,8 @@ void ContactsManager::on_update_user_usernames(User *u, UserId user_id, Username
|
||||
u->is_username_changed = true;
|
||||
LOG(DEBUG) << "Usernames have changed for " << user_id;
|
||||
u->is_changed = true;
|
||||
} else {
|
||||
td_->messages_manager_->on_dialog_usernames_received(DialogId(user_id), usernames, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16176,8 +16185,8 @@ void ContactsManager::on_update_channel_usernames(ChannelId channel_id, Username
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_usernames(Channel *c, ChannelId channel_id, Usernames &&usernames) {
|
||||
td_->messages_manager_->on_dialog_usernames_updated(DialogId(channel_id), c->usernames, usernames);
|
||||
if (c->usernames != usernames) {
|
||||
td_->messages_manager_->on_dialog_usernames_updated(DialogId(channel_id), c->usernames, usernames);
|
||||
if (c->is_update_supergroup_sent) {
|
||||
on_channel_usernames_changed(c, channel_id, c->usernames, usernames);
|
||||
}
|
||||
@ -16185,6 +16194,8 @@ void ContactsManager::on_update_channel_usernames(Channel *c, ChannelId channel_
|
||||
c->usernames = std::move(usernames);
|
||||
c->is_username_changed = true;
|
||||
c->is_changed = true;
|
||||
} else {
|
||||
td_->messages_manager_->on_dialog_usernames_received(DialogId(channel_id), usernames, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32814,28 +32814,34 @@ void MessagesManager::on_get_dialog_query_finished(DialogId dialog_id, Status &&
|
||||
void MessagesManager::on_dialog_usernames_updated(DialogId dialog_id, const Usernames &old_usernames,
|
||||
const Usernames &new_usernames) {
|
||||
CHECK(dialog_id.is_valid());
|
||||
const auto *d = get_dialog(dialog_id);
|
||||
if (d != nullptr) {
|
||||
update_dialogs_hints(d);
|
||||
}
|
||||
if (old_usernames != new_usernames) {
|
||||
message_embedding_codes_[0].erase(dialog_id);
|
||||
message_embedding_codes_[1].erase(dialog_id);
|
||||
LOG(INFO) << "Update usernames in " << dialog_id << " from " << old_usernames << " to " << new_usernames;
|
||||
|
||||
LOG(INFO) << "Update usernames in " << dialog_id << " from " << old_usernames << " to " << new_usernames;
|
||||
}
|
||||
if (!old_usernames.is_empty() && old_usernames != new_usernames) {
|
||||
message_embedding_codes_[0].erase(dialog_id);
|
||||
message_embedding_codes_[1].erase(dialog_id);
|
||||
|
||||
if (!old_usernames.is_empty()) {
|
||||
for (auto &username : old_usernames.get_active_usernames()) {
|
||||
auto cleaned_username = clean_username(username);
|
||||
resolved_usernames_.erase(cleaned_username);
|
||||
inaccessible_resolved_usernames_.erase(cleaned_username);
|
||||
}
|
||||
}
|
||||
if (!new_usernames.is_empty()) {
|
||||
for (auto &username : new_usernames.get_active_usernames()) {
|
||||
|
||||
on_dialog_usernames_received(dialog_id, new_usernames, false);
|
||||
}
|
||||
|
||||
void MessagesManager::on_dialog_usernames_received(DialogId dialog_id, const Usernames &usernames, bool from_database) {
|
||||
const auto *d = get_dialog(dialog_id);
|
||||
if (d != nullptr) {
|
||||
update_dialogs_hints(d);
|
||||
}
|
||||
|
||||
if (!usernames.is_empty()) {
|
||||
for (auto &username : usernames.get_active_usernames()) {
|
||||
auto cleaned_username = clean_username(username);
|
||||
if (!cleaned_username.empty()) {
|
||||
resolved_usernames_[cleaned_username] = ResolvedUsername{dialog_id, Time::now() + USERNAME_CACHE_EXPIRE_TIME};
|
||||
resolved_usernames_[cleaned_username] =
|
||||
ResolvedUsername{dialog_id, Time::now() + (from_database ? 0 : USERNAME_CACHE_EXPIRE_TIME)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -891,6 +891,7 @@ class MessagesManager final : public Actor {
|
||||
void on_dialog_photo_updated(DialogId dialog_id);
|
||||
void on_dialog_title_updated(DialogId dialog_id);
|
||||
void on_dialog_usernames_updated(DialogId dialog_id, const Usernames &old_usernames, const Usernames &new_usernames);
|
||||
void on_dialog_usernames_received(DialogId dialog_id, const Usernames &usernames, bool from_database);
|
||||
void on_dialog_default_permissions_updated(DialogId dialog_id);
|
||||
void on_dialog_has_protected_content_updated(DialogId dialog_id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user