From edd3bb94a451c62f502d1d94671d525201f3e87f Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 25 Oct 2019 17:04:01 +0300 Subject: [PATCH] Add td_api::remoteFile.unique_id. GitOrigin-RevId: b6355e905d7268aefbb4dd2e951b15e12504ee54 --- td/generate/scheme/td_api.tl | 6 ++++-- td/generate/scheme/td_api.tlo | Bin 163360 -> 163396 bytes td/telegram/InlineQueriesManager.cpp | 4 ++-- td/telegram/files/FileLocation.h | 10 ++++++++++ td/telegram/files/FileLocation.hpp | 11 +++++++++++ td/telegram/files/FileManager.cpp | 18 ++++++++++++++++-- td/telegram/files/FileManager.h | 3 +++ 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e86b296d0..4b6f8923e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -138,12 +138,14 @@ temporaryPasswordState has_password:Bool valid_for:int32 = TemporaryPasswordStat localFile path:string can_be_downloaded:Bool can_be_deleted:Bool is_downloading_active:Bool is_downloading_completed:Bool download_offset:int32 downloaded_prefix_size:int32 downloaded_size:int32 = LocalFile; //@description Represents a remote file -//@id Remote file identifier; may be empty. Can be used across application restarts or even from other devices for the current user. If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. TDLib is currently unable to download files if only their URL is known. +//@id Remote file identifier; may be empty. Can be used across application restarts or even from other devices for the current user. Uniquely identifies a file, but a file can have a lot of different valid identifiers. +//-If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. TDLib is currently unable to download files if only their URL is known. //-If downloadFile is called on such a file or if it is sent to a secret chat, TDLib starts a file generation process by sending updateFileGenerationStart to the client with the HTTP URL in the original_path and "#url#" as the conversion string. Clients should generate the file by downloading it to the specified location +//@unique_id Unique file identifier; may be empty if unknown. The unique file identifier which is the same for the same file even for different users and is persistent over time //@is_uploading_active True, if the file is currently being uploaded (or a remote copy is being generated by some other means) //@is_uploading_completed True, if a remote copy is fully available //@uploaded_size Size of the remote available part of the file; 0 if unknown -remoteFile id:string is_uploading_active:Bool is_uploading_completed:Bool uploaded_size:int32 = RemoteFile; +remoteFile id:string unique_id:string is_uploading_active:Bool is_uploading_completed:Bool uploaded_size:int32 = RemoteFile; //@description Represents a file //@id Unique file identifier diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 3570a5e13dfc20a1e393816b21be6a84d292493c..2f4d06664e20df8c0028b75ea2dffd8a06ff28d6 100644 GIT binary patch delta 100 zcmZ4Rhx5oE&J7XrESG#!CU1_B|B=oLVlhsisKg|{xuU)1gb0YwRg{{WUy|yUnUl%@ w;!nS@fl*?z!Ylz!&eFWh!qU|E%;|jR@Bjb+ delta 79 zcmX@|hjYOn&J7XrEFx;ZGd9P_|40Y3rUytcDQvE2uQ?$ClHe*z&CM@Kb<502WdQLf ZJ51A<9umOV0ao1pAb@fEg8-%!T>t_+9|!;d diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index e49518208..153e8bf8b 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -837,8 +837,8 @@ td_api::object_ptr copy(const td_api::localFile &obj) { } template <> td_api::object_ptr copy(const td_api::remoteFile &obj) { - return td_api::make_object(obj.id_, obj.is_uploading_active_, obj.is_uploading_completed_, - obj.uploaded_size_); + return td_api::make_object(obj.id_, obj.unique_id_, obj.is_uploading_active_, + obj.is_uploading_completed_, obj.uploaded_size_); } template <> diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 241a10e7f..3320b9023 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -284,6 +284,16 @@ class FullRemoteFileLocation { return AsKey{*this}; } + struct AsUnique { + const FullRemoteFileLocation &key; + + template + void store(StorerT &storer) const; + }; + AsUnique as_unique() const { + return AsUnique{*this}; + } + DcId get_dc_id() const { CHECK(!is_web()); return dc_id_; diff --git a/td/telegram/files/FileLocation.hpp b/td/telegram/files/FileLocation.hpp index 28532680c..0996eb284 100644 --- a/td/telegram/files/FileLocation.hpp +++ b/td/telegram/files/FileLocation.hpp @@ -202,6 +202,17 @@ void FullRemoteFileLocation::AsKey::store(StorerT &storer) const { }); } +template +void FullRemoteFileLocation::AsUnique::store(StorerT &storer) const { + using td::store; + + store(key.location_type(), storer); + key.variant_.visit([&](auto &&value) { + using td::store; + store(value.as_key(), storer); + }); +} + template void RemoteFileLocation::store(StorerT &storer) const { td::store(variant_, storer); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index b9a972d8b..99690ab2e 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2665,6 +2665,14 @@ static bool is_background_type(FileType type) { return type == FileType::Wallpaper || type == FileType::Background; } +string FileManager::get_unique_id(const FullGenerateFileLocation &location) { + return base64url_encode(zero_encode('\xff' + serialize(location))); +} + +string FileManager::get_unique_id(const FullRemoteFileLocation &location) { + return base64url_encode(zero_encode(serialize(location.as_unique()))); +} + string FileManager::get_persistent_id(const FullGenerateFileLocation &location) { auto binary = serialize(location); @@ -2672,6 +2680,7 @@ string FileManager::get_persistent_id(const FullGenerateFileLocation &location) binary.push_back(PERSISTENT_ID_VERSION_MAP); return base64url_encode(binary); } + string FileManager::get_persistent_id(const FullRemoteFileLocation &location) { auto location_copy = location; location_copy.clear_file_reference(); @@ -2805,12 +2814,17 @@ td_api::object_ptr FileManager::get_file_object(FileId file_id, bo } string persistent_file_id; + string unique_file_id; if (file_view.has_alive_remote_location()) { persistent_file_id = get_persistent_id(file_view.remote_location()); + if (!file_view.remote_location().is_web()) { + unique_file_id = get_unique_id(file_view.remote_location()); + } } else if (file_view.has_url()) { persistent_file_id = file_view.url(); } else if (file_view.has_generate_location() && begins_with(file_view.generate_location().conversion_, "#map#")) { persistent_file_id = get_persistent_id(file_view.generate_location()); + unique_file_id = get_unique_id(file_view.generate_location()); } bool is_uploading_completed = !persistent_file_id.empty(); @@ -2841,8 +2855,8 @@ td_api::object_ptr FileManager::get_file_object(FileId file_id, bo td_api::make_object(std::move(path), can_be_downloaded, can_be_deleted, file_view.is_downloading(), file_view.has_local_location(), download_offset, local_prefix_size, local_total_size), - td_api::make_object(std::move(persistent_file_id), file_view.is_uploading(), - is_uploading_completed, remote_size)); + td_api::make_object(std::move(persistent_file_id), std::move(unique_file_id), + file_view.is_uploading(), is_uploading_completed, remote_size)); } vector FileManager::get_file_ids_object(const vector &file_ids, bool with_main_file_id) { diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 9ac93d3b6..0a636d009 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -579,6 +579,9 @@ class FileManager : public FileLoadManager::Callback { void flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate, const char *source); void load_from_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate); + string get_unique_id(const FullGenerateFileLocation &location); + string get_unique_id(const FullRemoteFileLocation &location); + string get_persistent_id(const FullGenerateFileLocation &location); string get_persistent_id(const FullRemoteFileLocation &location);