From d04a1a61ccde3d9e82e6d7d5c058c85a59b93c04 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 22 Jan 2019 17:35:29 +0300 Subject: [PATCH] Add wallpapers file source for wallpapers registered by remote location. GitOrigin-RevId: a0994ef92ef927d780acf6a79cfad5b424d93784 --- td/telegram/FileReferenceManager.cpp | 2 +- td/telegram/Td.cpp | 4 ++-- td/telegram/WallpaperManager.cpp | 7 +++++++ td/telegram/WallpaperManager.h | 2 ++ td/telegram/files/FileManager.cpp | 8 +++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index ae4cab13f..ba17eb0d3 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -64,7 +64,7 @@ FileSourceId FileReferenceManager::create_channel_photo_file_source(ChannelId ch } FileSourceId FileReferenceManager::create_wallpapers_file_source() { - FileSourceWebPage source; + FileSourceWallpapers source; return add_file_source_id(source, "wallpapers"); } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2a3224b5e..0c8ad4bf3 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4850,8 +4850,8 @@ void Td::on_request(uint64 id, const td_api::getFileDownloadedPrefixSize &reques void Td::on_request(uint64 id, td_api::getRemoteFile &request) { CLEAN_INPUT_STRING(request.remote_file_id_); - auto r_file_id = file_manager_->from_persistent_id( - request.remote_file_id_, request.file_type_ == nullptr ? FileType::Temp : from_td_api(*request.file_type_)); + auto file_type = request.file_type_ == nullptr ? FileType::Temp : from_td_api(*request.file_type_); + auto r_file_id = file_manager_->from_persistent_id(request.remote_file_id_, file_type); if (r_file_id.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_file_id.move_as_error()); } else { diff --git a/td/telegram/WallpaperManager.cpp b/td/telegram/WallpaperManager.cpp index 4a28b6b4d..32f13dd45 100644 --- a/td/telegram/WallpaperManager.cpp +++ b/td/telegram/WallpaperManager.cpp @@ -127,6 +127,13 @@ void WallpaperManager::on_get_wallpapers(Resultfile_reference_manager_->create_wallpapers_file_source(); + } + td_->file_manager_->add_file_source(file_id, wallpaper_source_id_); +} + td_api::object_ptr WallpaperManager::get_wallpapers_object() const { return td_api::make_object( transform(wallpapers_, [file_manager = td_->file_manager_.get()](const Wallpaper &wallpaper) { diff --git a/td/telegram/WallpaperManager.h b/td/telegram/WallpaperManager.h index 408d3ccee..8dfbc0e16 100644 --- a/td/telegram/WallpaperManager.h +++ b/td/telegram/WallpaperManager.h @@ -31,6 +31,8 @@ class WallpaperManager : public Actor { td_api::object_ptr get_wallpapers_object() const; + void add_wallpapers_file_source(FileId file_id); + private: void tear_down() override; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index e49ad44ac..cb71de547 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -18,6 +18,7 @@ #include "td/telegram/misc.h" #include "td/telegram/SecureStorage.h" #include "td/telegram/TdDb.h" +#include "td/telegram/WallpaperManager.h" #include "td/utils/base64.h" #include "td/utils/format.h" @@ -2199,7 +2200,12 @@ Result FileManager::from_persistent_id_v2(Slice binary, FileType file_ty } FileData data; data.remote_ = RemoteFileLocation(std::move(remote_location)); - return register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_v2", false).move_as_ok(); + auto file_id = + register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_v2", false).move_as_ok(); + if (real_file_type == FileType::Wallpaper && file_id.is_valid()) { + send_closure(G()->wallpaper_manager(), &WallpaperManager::add_wallpapers_file_source, file_id); + } + return file_id; } FileView FileManager::get_file_view(FileId file_id) const {