Store correspondence between message and FileSourceId in MessagesManager.

GitOrigin-RevId: 1fc23f6032c473639ce24e6564632d80327d24b3
This commit is contained in:
levlam 2019-01-18 21:24:03 +03:00
parent 5bba9b0470
commit 1f5a86ea58
4 changed files with 17 additions and 13 deletions

View File

@ -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);

View File

@ -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<FileSourceMessage, FileSourceUserPhoto, FileSourceChatPhoto, FileSourceChannelPhoto,
FileSourceWallpapers, FileSourceWebPage, FileSourceSavedAnimations>;
vector<FileSource> file_sources_;
std::unordered_map<FullMessageId, FileSourceId, FullMessageIdHash> full_message_id_to_file_source_id_;
int32 last_file_source_id_{0};
int64 query_generation{0};

View File

@ -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);
}

View File

@ -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<DialogId, NetQueryRef, DialogIdHash> set_typing_query_;
std::unordered_map<FullMessageId, FileSourceId, FullMessageIdHash> full_message_id_to_file_source_id_;
DialogId sponsored_dialog_id_;
DialogId being_added_dialog_id_;