From 369345f47c96795b26b7100048c0061fe2721c37 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 19 Dec 2019 00:31:01 +0300 Subject: [PATCH] Add ContactsManager::for_each_secret_chat_with_user. GitOrigin-RevId: bf81c627a6d4cf00ff5b6c8882079cce23d636f3 --- td/telegram/ContactsManager.cpp | 29 +++++++++++++++++------------ td/telegram/ContactsManager.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 6ec8086a0..7d522ff82 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7810,6 +7810,15 @@ ContactsManager::ChannelFull *ContactsManager::get_channel_full_force(ChannelId return get_channel_full(channel_id); } +void ContactsManager::for_each_secret_chat_with_user(UserId user_id, std::function f) { + auto it = secret_chats_with_user_.find(user_id); + if (it != secret_chats_with_user_.end()) { + for (auto secret_chat_id : it->second) { + f(secret_chat_id); + } + } +} + void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, bool from_database) { CHECK(u != nullptr); if (u->is_name_changed || u->is_username_changed || u->is_is_contact_changed) { @@ -7836,21 +7845,17 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo } if (u->is_name_changed) { td_->messages_manager_->on_dialog_title_updated(DialogId(user_id)); - auto it = secret_chats_with_user_.find(user_id); - if (it != secret_chats_with_user_.end()) { - for (auto secret_chat_id : it->second) { - td_->messages_manager_->on_dialog_title_updated(DialogId(secret_chat_id)); - } - } + for_each_secret_chat_with_user(user_id, + [messages_manager = td_->messages_manager_.get()](SecretChatId secret_chat_id) { + messages_manager->on_dialog_title_updated(DialogId(secret_chat_id)); + }); } if (u->is_photo_changed) { td_->messages_manager_->on_dialog_photo_updated(DialogId(user_id)); - auto it = secret_chats_with_user_.find(user_id); - if (it != secret_chats_with_user_.end()) { - for (auto secret_chat_id : it->second) { - td_->messages_manager_->on_dialog_photo_updated(DialogId(secret_chat_id)); - } - } + for_each_secret_chat_with_user(user_id, + [messages_manager = td_->messages_manager_.get()](SecretChatId secret_chat_id) { + messages_manager->on_dialog_photo_updated(DialogId(secret_chat_id)); + }); add_user_photo_id(u, user_id, u->photo.id, dialog_photo_get_file_ids(u->photo)); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 94a0c4013..679649d83 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -117,6 +117,8 @@ class ContactsManager : public Actor { bool is_update_about_username_change_received(UserId user_id) const; + void for_each_secret_chat_with_user(UserId user_id, std::function f); + string get_user_username(UserId user_id) const; string get_channel_username(ChannelId channel_id) const; string get_secret_chat_username(SecretChatId secret_chat_id) const;