From 1f5a86ea585b77d21625745da39dbd104ee553a6 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 18 Jan 2019 21:24:03 +0300 Subject: [PATCH] Store correspondence between message and FileSourceId in MessagesManager. GitOrigin-RevId: 1fc23f6032c473639ce24e6564632d80327d24b3 --- td/telegram/FileReferenceManager.cpp | 8 ++------ td/telegram/FileReferenceManager.h | 4 +--- td/telegram/MessagesManager.cpp | 14 ++++++++++---- td/telegram/MessagesManager.h | 4 ++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 75b781b96..55468c9ca 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -34,15 +34,10 @@ fileSourceSavedAnimations = FileSource; // repair */ FileSourceId FileReferenceManager::create_message_file_source(FullMessageId full_message_id) { - auto it = full_message_id_to_file_source_id_.find(full_message_id); - if (it != full_message_id_to_file_source_id_.end()) { - return it->second; - } - + VLOG(file_references) << "Create file source for " << full_message_id; auto source_id = FileSourceId{++last_file_source_id_}; FileSourceMessage source{full_message_id}; file_sources_.emplace_back(source); - full_message_id_to_file_source_id_[full_message_id] = source_id; return source_id; } @@ -50,6 +45,7 @@ void FileReferenceManager::add_file_source(NodeId node_id, FileSourceId file_sou VLOG(file_references) << "add_file_source: " << node_id << " " << file_source_id; nodes_[node_id].file_source_ids.add(file_source_id); } + void FileReferenceManager::remove_file_source(NodeId node_id, FileSourceId file_source_id) { VLOG(file_references) << "remove_file_source: " << node_id << " " << file_source_id; nodes_[node_id].file_source_ids.remove(file_source_id); diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index f8c2534fc..37173c8cc 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -60,8 +60,8 @@ class FileReferenceManager : public Actor { FullMessageId full_message_id; }; struct FileSourceUserPhoto { - UserId user_id; int64 photo_id; + UserId user_id; }; struct FileSourceChatPhoto { ChatId chat_id; @@ -81,9 +81,7 @@ class FileReferenceManager : public Actor { using FileSource = Variant; - vector file_sources_; - std::unordered_map full_message_id_to_file_source_id_; int32 last_file_source_id_{0}; int64 query_generation{0}; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 70c4623de..e3ffd244b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13697,6 +13697,14 @@ void MessagesManager::save_active_live_locations() { } } +FileSourceId MessagesManager::get_message_file_source_id(FullMessageId full_message_id) { + auto &file_source_id = full_message_id_to_file_source_id_[full_message_id]; + if (!file_source_id.is_valid()) { + file_source_id = td_->file_reference_manager_->create_message_file_source(full_message_id); + } + return file_source_id; +} + void MessagesManager::add_message_file_sources(DialogId dialog_id, const Message *m) { if (dialog_id.get_type() == DialogType::SecretChat || !m->message_id.is_server()) { return; @@ -13707,8 +13715,7 @@ void MessagesManager::add_message_file_sources(DialogId dialog_id, const Message return; } - auto file_source_id = - td_->file_reference_manager_->create_message_file_source(FullMessageId(dialog_id, m->message_id)); + auto file_source_id = get_message_file_source_id(FullMessageId(dialog_id, m->message_id)); for (auto file_id : file_ids) { td_->file_manager_->add_file_source(file_id, file_source_id); } @@ -13724,8 +13731,7 @@ void MessagesManager::remove_message_file_sources(DialogId dialog_id, const Mess return; } - auto file_source_id = - td_->file_reference_manager_->create_message_file_source(FullMessageId(dialog_id, m->message_id)); + auto file_source_id = get_message_file_source_id(FullMessageId(dialog_id, m->message_id)); for (auto file_id : file_ids) { td_->file_manager_->remove_file_source(file_id, file_source_id); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index b32e6e37e..d4093ca91 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1841,6 +1841,8 @@ class MessagesManager : public Actor { void save_active_live_locations(); + FileSourceId get_message_file_source_id(FullMessageId full_message_id); + void add_message_file_sources(DialogId dialog_id, const Message *m); void remove_message_file_sources(DialogId dialog_id, const Message *m); @@ -2300,6 +2302,8 @@ class MessagesManager : public Actor { std::unordered_map set_typing_query_; + std::unordered_map full_message_id_to_file_source_id_; + DialogId sponsored_dialog_id_; DialogId being_added_dialog_id_;