diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 84bde43e..b572a278 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -38,11 +38,52 @@ FileSourceId FileReferenceManager::get_current_file_source_id() const { return FileSourceId(narrow_cast(file_sources_.size())); } +template +FileSourceId FileReferenceManager::add_file_source_id(T source) { + file_sources_.emplace_back(std::move(source)); + return get_current_file_source_id(); +} + FileSourceId FileReferenceManager::create_message_file_source(FullMessageId full_message_id) { VLOG(file_references) << "Create file source for " << full_message_id; FileSourceMessage source{full_message_id}; - file_sources_.emplace_back(source); - return get_current_file_source_id(); + return add_file_source_id(source); +} + +FileSourceId FileReferenceManager::create_user_photo_file_source(UserId user_id, int64 photo_id) { + VLOG(file_references) << "Create file source for photo " << photo_id << " of " << user_id; + FileSourceUserPhoto source{photo_id, user_id}; + return add_file_source_id(source); +} + +FileSourceId FileReferenceManager::create_chat_photo_file_source(ChatId chat_id) { + VLOG(file_references) << "Create file source for photo of " << chat_id; + FileSourceChatPhoto source{chat_id}; + return add_file_source_id(source); +} + +FileSourceId FileReferenceManager::create_channel_photo_file_source(ChannelId channel_id) { + VLOG(file_references) << "Create file source for photo of " << channel_id; + FileSourceChannelPhoto source{channel_id}; + return add_file_source_id(source); +} + +FileSourceId FileReferenceManager::create_wallpapers_file_source() { + VLOG(file_references) << "Create file source for wallpapers"; + FileSourceWebPage source; + return add_file_source_id(source); +} + +FileSourceId FileReferenceManager::create_web_page_file_source(string url) { + VLOG(file_references) << "Create file source for web page of " << url; + FileSourceWebPage source{std::move(url)}; + return add_file_source_id(std::move(source)); +} + +FileSourceId FileReferenceManager::create_saved_animations_file_source() { + VLOG(file_references) << "Create file source for saved animations"; + FileSourceSavedAnimations source; + return add_file_source_id(source); } void FileReferenceManager::add_file_source(NodeId node_id, FileSourceId file_source_id) { @@ -73,7 +114,7 @@ void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) { if (to.query || from.query) { if (!to.query) { to.query = make_unique(); - to.query->generation = ++query_generation; + to.query->generation = ++query_generation_; } if (from.query) { ::td::merge(to.query->promises, from.query->promises); @@ -221,11 +262,12 @@ void FileReferenceManager::update_file_reference(NodeId node_id, Promise<> promi auto &node = nodes_[node_id]; if (!node.query) { node.query = make_unique(); - node.query->generation = ++query_generation; + node.query->generation = ++query_generation_; node.file_source_ids.reset_position(); - VLOG(file_references) << "new query " << query_generation; + VLOG(file_references) << "new query " << query_generation_; } node.query->promises.push_back(std::move(promise)); run_node(node_id); } + } // namespace td diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index 42f2fdc3..72a08645 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -25,10 +25,14 @@ namespace td { extern int VERBOSITY_NAME(file_references); class FileReferenceManager : public Actor { - struct Node; - public: FileSourceId create_message_file_source(FullMessageId full_message_id); + FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id); + FileSourceId create_chat_photo_file_source(ChatId chat_id); + FileSourceId create_channel_photo_file_source(ChannelId channel_id); + FileSourceId create_wallpapers_file_source(); + FileSourceId create_web_page_file_source(string url); + FileSourceId create_saved_animations_file_source(); using NodeId = FileId; void update_file_reference(NodeId node_id, Promise<> promise); @@ -83,7 +87,7 @@ class FileReferenceManager : public Actor { FileSourceWallpapers, FileSourceWebPage, FileSourceSavedAnimations>; vector file_sources_; - int64 query_generation{0}; + int64 query_generation_{0}; std::unordered_map nodes_; @@ -91,6 +95,9 @@ class FileReferenceManager : public Actor { void send_query(Destination dest, FileSourceId file_source_id); Destination on_query_result(Destination dest, FileSourceId file_source_id, Status status, int32 sub = 0); + template + FileSourceId add_file_source_id(T source); + FileSourceId get_current_file_source_id() const; };