diff --git a/CMakeLists.txt b/CMakeLists.txt index d51bca79c..b5eb98707 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,7 @@ set(TDLIB_SOURCE td/telegram/AnimationsManager.cpp td/telegram/AudiosManager.cpp td/telegram/AuthManager.cpp + td/telegram/BackgroundManager.cpp td/telegram/CallActor.cpp td/telegram/CallDiscardReason.cpp td/telegram/CallManager.cpp @@ -452,7 +453,6 @@ set(TDLIB_SOURCE td/telegram/VideoNotesManager.cpp td/telegram/VideosManager.cpp td/telegram/VoiceNotesManager.cpp - td/telegram/WallpaperManager.cpp td/telegram/WebPageBlock.cpp td/telegram/WebPagesManager.cpp @@ -483,6 +483,8 @@ set(TDLIB_SOURCE td/telegram/AnimationsManager.h td/telegram/AudiosManager.h td/telegram/AuthManager.h + td/telegram/BackgroundId.h + td/telegram/BackgroundManager.h td/telegram/CallActor.h td/telegram/CallDiscardReason.h td/telegram/CallId.h @@ -619,7 +621,6 @@ set(TDLIB_SOURCE td/telegram/VideoNotesManager.h td/telegram/VideosManager.h td/telegram/VoiceNotesManager.h - td/telegram/WallpaperManager.h td/telegram/WebPageBlock.h td/telegram/WebPageId.h td/telegram/WebPagesManager.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b214c89fe..2c675cdd7 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -91,7 +91,7 @@ authorizationStateWaitPhoneNumber = AuthorizationState; //@description TDLib needs the user's authentication code to finalize authorization @is_registered True, if the user is already registered @terms_of_service Telegram terms of service, which should be accepted before user can continue registration; may be null @code_info Information about the authorization code that was sent authorizationStateWaitCode is_registered:Bool terms_of_service:termsOfService code_info:authenticationCodeInfo = AuthorizationState; -//@description The user has been authorized, but needs to enter a password to start using the application @password_hint Hint for the password; may be empty @has_recovery_email_address True if a recovery email address has been set up +//@description The user has been authorized, but needs to enter a password to start using the application @password_hint Hint for the password; may be empty @has_recovery_email_address True, if a recovery email address has been set up //@recovery_email_address_pattern Pattern of the email address to which the recovery email was sent; empty until a recovery email has been sent authorizationStateWaitPassword password_hint:string has_recovery_email_address:Bool recovery_email_address_pattern:string = AuthorizationState; @@ -210,7 +210,7 @@ animation duration:int32 width:int32 height:int32 file_name:string mime_type:str audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:photoSize audio:file = Audio; //@description Describes a document of any type @file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender -//@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail; as defined by the sender; may be null @document File containing the document +//@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail in JPEG or PNG format (PNG will be used only for background patterns); as defined by the sender; may be null @document File containing the document document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:photoSize document:file = Document; //@description Describes a photo @has_stickers True, if stickers were added to the photo @minithumbnail Photo minithumbnail; may be null @sizes Available variants of the photo, in different sizes @@ -1939,11 +1939,34 @@ deviceTokenTizenPush reg_id:string = DeviceToken; pushReceiverId id:int64 = PushReceiverId; -//@description Contains information about a wallpaper @id Unique persistent wallpaper identifier @sizes Available variants of the wallpaper in different sizes. These photos can only be downloaded; they can't be sent in a message @color Main color of the wallpaper in RGB24 format; should be treated as background color if no photos are specified -wallpaper id:int32 sizes:vector color:int32 = Wallpaper; +//@class BackgroundType @description Describes a type of a background -//@description Contains a list of wallpapers @wallpapers A list of wallpapers -wallpapers wallpapers:vector = Wallpapers; +//@description A wallpaper in JPEG format +//@is_blurred True, if the wallpaper must be downscaled to fit in 450x450 square and then box-blurred with radius 12 +//@is_moving True, if the background needs to be slightly moved when device is rotated +backgroundTypeWallpaper is_blurred:Bool is_moving:Bool = BackgroundType; + +//@description A PNG pattern to be combined with the chosen by the user color +//@is_moving True, if the background needs to be slightly moved when device is rotated +//@color Main color of the background in RGB24 format +//@intensity Intensity of the pattern when it is shown above the main background color, 0-100 +backgroundTypePattern is_moving:Bool color:int32 intensity:int32 = BackgroundType; + +//@description A solid background @color A color of the background in RGB24 format +backgroundTypeSolid color:int32 = BackgroundType; + + +//@description Describes a chat background +//@id Unique background identifier +//@is_default True, if this is one of default backgrounds +//@is_dark True, if this background is dark and is recommended to be used with dark theme +//@name Unique background name +//@document Document with the background; may be null. Null only for solid backgrounds +//@type Type of the background +background id:int64 is_default:Bool is_dark:Bool name:string document:document type:BackgroundType = Background; + +//@description Contains a list of backgrounds @backgrounds A list of backgrounds +backgrounds backgrounds:vector = Backgrounds; //@description Contains a list of hashtags @hashtags A list of hashtags @@ -2283,7 +2306,7 @@ fileTypeVideoNote = FileType; //@description The file is a voice note fileTypeVoiceNote = FileType; -//@description The file is a wallpaper +//@description The file is a wallpaper or a background pattern fileTypeWallpaper = FileType; @@ -3578,8 +3601,8 @@ deleteSavedCredentials = Ok; //@description Returns a user that can be contacted to get support getSupportUser = User; -//@description Returns background wallpapers -getWallpapers = Wallpapers; +//@description Returns backgrounds installed by the user +getBackgrounds = Backgrounds; //@description Returns information about the current localization target. This is an offline request if only_local is true. Can be called before authorization @only_local If true, returns only locally available information without sending network requests diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 3a2df017b..0605e78dd 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/BackgroundId.h b/td/telegram/BackgroundId.h new file mode 100644 index 000000000..b07a1b9f5 --- /dev/null +++ b/td/telegram/BackgroundId.h @@ -0,0 +1,66 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" +#include "td/utils/tl_helpers.h" + +#include +#include + +namespace td { + +class BackgroundId { + int64 id = 0; + + public: + BackgroundId() = default; + + explicit BackgroundId(int64 background_id) : id(background_id) { + } + template ::value>> + BackgroundId(T background_id) = delete; + + int64 get() const { + return id; + } + + bool operator==(const BackgroundId &other) const { + return id == other.id; + } + + bool operator!=(const BackgroundId &other) const { + return id != other.id; + } + + bool is_valid() const { + return id != 0; + } + + template + void store(StorerT &storer) const { + td::store(id, storer); + } + + template + void parse(ParserT &parser) { + td::parse(id, parser); + } +}; + +struct BackgroundIdHash { + std::size_t operator()(BackgroundId background_id) const { + return std::hash()(background_id.get()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, BackgroundId background_id) { + return string_builder << "background " << background_id.get(); +} + +} // namespace td diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp new file mode 100644 index 000000000..87ace2ed8 --- /dev/null +++ b/td/telegram/BackgroundManager.cpp @@ -0,0 +1,227 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/BackgroundManager.h" + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/telegram/DialogId.h" +#include "td/telegram/Document.h" +#include "td/telegram/DocumentsManager.h" +#include "td/telegram/FileReferenceManager.h" +#include "td/telegram/files/FileManager.h" +#include "td/telegram/files/FileType.h" +#include "td/telegram/Global.h" +#include "td/telegram/Photo.h" +#include "td/telegram/Td.h" + +#include "td/utils/buffer.h" +#include "td/utils/common.h" +#include "td/utils/misc.h" + +namespace td { + +class GetBackgroundsQuery : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetBackgroundsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getWallPapers(0)))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + promise_.set_value(result_ptr.move_as_ok()); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + +BackgroundManager::BackgroundManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { +} + +void BackgroundManager::tear_down() { + parent_.reset(); +} + +void BackgroundManager::get_backgrounds(Promise &&promise) { + pending_get_backgrounds_queries_.push_back(std::move(promise)); + if (pending_get_backgrounds_queries_.size() == 1) { + auto request_promise = PromiseCreator::lambda( + [actor_id = actor_id(this)](Result> result) { + send_closure(actor_id, &BackgroundManager::on_get_backgrounds, std::move(result)); + }); + + td_->create_handler(std::move(request_promise))->send(); + } +} + +BackgroundManager::Background *BackgroundManager::add_background(BackgroundId background_id) { + CHECK(background_id.is_valid()); + return &backgrounds_[background_id]; +} + +const BackgroundManager::Background *BackgroundManager::get_background(BackgroundId background_id) const { + auto p = backgrounds_.find(background_id); + if (p == backgrounds_.end()) { + return nullptr; + } else { + return &p->second; + } +} + +BackgroundManager::BackgroundType BackgroundManager::get_background_type( + bool is_pattern, telegram_api::object_ptr settings) { + bool is_blurred = false; + bool is_moving = false; + int32 color = 0; + int32 intensity = 0; + if (settings) { + auto flags = settings->flags_; + is_blurred = (flags & telegram_api::wallPaperSettings::BLUR_MASK) != 0; + is_moving = (flags & telegram_api::wallPaperSettings::MOTION_MASK) != 0; + if ((flags & telegram_api::wallPaperSettings::BACKGROUND_COLOR_MASK) != 0) { + color = settings->background_color_; + if (color < 0 || color > 0xFFFFFF) { + LOG(ERROR) << "Receive " << to_string(settings); + color = 0; + } + } + if ((flags & telegram_api::wallPaperSettings::INTENSITY_MASK) != 0) { + intensity = settings->intensity_; + if (intensity < 0 || intensity > 100) { + LOG(ERROR) << "Receive " << to_string(settings); + intensity = 0; + } + } + } + if (is_pattern) { + return BackgroundType(is_moving, color, intensity); + } else { + return BackgroundType(is_blurred, is_moving); + } +} + +BackgroundId BackgroundManager::on_get_background(telegram_api::object_ptr wallpaper) { + CHECK(wallpaper != nullptr); + + auto id = BackgroundId(wallpaper->id_); + if (!id.is_valid()) { + LOG(ERROR) << "Receive " << to_string(wallpaper); + return BackgroundId(); + } + + int32 document_id = wallpaper->document_->get_id(); + if (document_id == telegram_api::documentEmpty::ID) { + LOG(ERROR) << "Receive " << to_string(wallpaper); + return BackgroundId(); + } + CHECK(document_id == telegram_api::document::ID); + + int32 flags = wallpaper->flags_; + bool is_pattern = (flags & telegram_api::wallPaper::PATTERN_MASK) != 0; + + Document document = td_->documents_manager_->on_get_document( + telegram_api::move_object_as(wallpaper->document_), DialogId(), nullptr, + Document::Type::General, true, is_pattern); + if (!document.file_id.is_valid()) { + LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper); + return BackgroundId(); + } + CHECK(document.type == Document::Type::General); + + auto *background = add_background(id); + background->id = id; + background->access_hash = wallpaper->access_hash_; + background->name = std::move(wallpaper->slug_); + background->file_id = document.file_id; + background->is_creator = (flags & telegram_api::wallPaper::CREATOR_MASK) != 0; + background->is_default = (flags & telegram_api::wallPaper::DEFAULT_MASK) != 0; + background->is_dark = (flags & telegram_api::wallPaper::DARK_MASK) != 0; + background->type = get_background_type(is_pattern, std::move(wallpaper->settings_)); + + return id; +} + +void BackgroundManager::on_get_backgrounds(Result> result) { + auto promises = std::move(pending_get_backgrounds_queries_); + CHECK(!promises.empty()); + reset_to_empty(pending_get_backgrounds_queries_); + + if (result.is_error()) { + // do not clear installed_backgrounds_ + + auto error = result.move_as_error(); + for (auto &promise : promises) { + promise.set_error(error.clone()); + } + return; + } + + auto wallpapers_ptr = result.move_as_ok(); + LOG(INFO) << "Receive " << to_string(wallpapers_ptr); + if (wallpapers_ptr->get_id() == telegram_api::account_wallPapersNotModified::ID) { + for (auto &promise : promises) { + promise.set_value(Unit()); + } + return; + } + + installed_backgrounds_.clear(); + auto wallpapers = telegram_api::move_object_as(wallpapers_ptr); + for (auto &wallpaper : wallpapers->wallpapers_) { + auto background_id = on_get_background(std::move(wallpaper)); + if (background_id.is_valid()) { + installed_backgrounds_.push_back(background_id); + } + } + + for (auto &promise : promises) { + promise.set_value(Unit()); + } +} + +td_api::object_ptr BackgroundManager::get_background_type_object(const BackgroundType &type) { + switch (type.type) { + case BackgroundType::Type::Wallpaper: + return td_api::make_object(type.is_blurred, type.is_moving); + case BackgroundType::Type::Pattern: + return td_api::make_object(type.is_moving, type.color, type.intensity); + case BackgroundType::Type::Solid: + return td_api::make_object(type.color); + default: + UNREACHABLE(); + return nullptr; + } +} + +td_api::object_ptr BackgroundManager::get_background_object(BackgroundId background_id) const { + auto background = get_background(background_id); + if (background == nullptr) { + return nullptr; + } + return td_api::make_object( + background->id.get(), background->is_default, background->is_dark, background->name, + td_->documents_manager_->get_document_object(background->file_id), get_background_type_object(background->type)); +} + +td_api::object_ptr BackgroundManager::get_backgrounds_object() const { + return td_api::make_object(transform( + installed_backgrounds_, [this](BackgroundId background_id) { return get_background_object(background_id); })); +} + +} // namespace td diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h new file mode 100644 index 000000000..9aaf958a5 --- /dev/null +++ b/td/telegram/BackgroundManager.h @@ -0,0 +1,94 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/BackgroundId.h" +#include "td/telegram/files/FileId.h" +#include "td/telegram/files/FileSourceId.h" +#include "td/telegram/Photo.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" + +#include "td/utils/common.h" +#include "td/utils/Status.h" + +#include + +namespace td { + +class Td; + +class BackgroundManager : public Actor { + public: + BackgroundManager(Td *td, ActorShared<> parent); + + void get_backgrounds(Promise &&promise); + + td_api::object_ptr get_background_object(BackgroundId background_id) const; + + td_api::object_ptr get_backgrounds_object() const; + + private: + struct BackgroundType { + enum class Type : int32 { Wallpaper, Pattern, Solid }; + Type type = Type::Solid; + bool is_blurred = false; + bool is_moving = false; + int32 color = 0; + int32 intensity = 0; + + BackgroundType() = default; + BackgroundType(bool is_blurred, bool is_moving) + : type(Type::Wallpaper), is_blurred(is_blurred), is_moving(is_moving) { + } + BackgroundType(bool is_moving, int32 color, int32 intensity) + : type(Type::Pattern), is_moving(is_moving), color(color), intensity(intensity) { + } + explicit BackgroundType(int32 color) : type(Type::Solid), color(color) { + } + }; + + struct Background { + BackgroundId id; + int64 access_hash = 0; + string name; + FileId file_id; + bool is_creator = false; + bool is_default = false; + bool is_dark = false; + BackgroundType type; + }; + + void tear_down() override; + + Background *add_background(BackgroundId background_id); + + const Background *get_background(BackgroundId background_id) const; + + static BackgroundType get_background_type(bool is_pattern, + telegram_api::object_ptr settings); + + BackgroundId on_get_background(telegram_api::object_ptr wallpaper); + + void on_get_backgrounds(Result> result); + + static td_api::object_ptr get_background_type_object(const BackgroundType &type); + + std::unordered_map backgrounds_; // id -> Background + + vector installed_backgrounds_; + + vector> pending_get_backgrounds_queries_; + + Td *td_; + ActorShared<> parent_; +}; + +} // namespace td diff --git a/td/telegram/Document.cpp b/td/telegram/Document.cpp index 571aeb1e3..c7ddd7cfe 100644 --- a/td/telegram/Document.cpp +++ b/td/telegram/Document.cpp @@ -48,31 +48,31 @@ vector Document::get_file_ids(const Td *td) const { return result; } -StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) { - auto type = [&] { - switch (document.type) { - case Document::Type::Unknown: - return "Unknown"; - case Document::Type::Animation: - return "Animation"; - case Document::Type::Audio: - return "Audio"; - case Document::Type::General: - return "Document"; - case Document::Type::Sticker: - return "Sticker"; - case Document::Type::Video: - return "Video"; - case Document::Type::VideoNote: - return "VideoNote"; - case Document::Type::VoiceNote: - return "VoiceNote"; - default: - return "Unreachable"; - } - }(); +StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type) { + switch (document_type) { + case Document::Type::Unknown: + return string_builder << "Unknown"; + case Document::Type::Animation: + return string_builder << "Animation"; + case Document::Type::Audio: + return string_builder << "Audio"; + case Document::Type::General: + return string_builder << "Document"; + case Document::Type::Sticker: + return string_builder << "Sticker"; + case Document::Type::Video: + return string_builder << "Video"; + case Document::Type::VideoNote: + return string_builder << "VideoNote"; + case Document::Type::VoiceNote: + return string_builder << "VoiceNote"; + default: + return string_builder << "Unreachable"; + } +} - return string_builder << '[' << type << ' ' << document.file_id << ']'; +StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) { + return string_builder << '[' << document.type << ' ' << document.file_id << ']'; } } // namespace td diff --git a/td/telegram/Document.h b/td/telegram/Document.h index 533931046..9a35bdfee 100644 --- a/td/telegram/Document.h +++ b/td/telegram/Document.h @@ -33,6 +33,8 @@ struct Document { vector get_file_ids(const Td *td) const; }; +StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type); + StringBuilder &operator<<(StringBuilder &string_builder, const Document &document); } // namespace td diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index f53d0d081..3466947fd 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -63,7 +63,7 @@ tl_object_ptr DocumentsManager::get_document_object(FileId fil Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id, MultiPromiseActor *load_data_multipromise_ptr, - Document::Type default_document_type) { + Document::Type default_document_type, bool is_background, bool is_pattern) { tl_object_ptr animated; tl_object_ptr video; tl_object_ptr audio; @@ -188,6 +188,21 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo << ", has_stickers = " << has_stickers; } + bool has_png_thumbnail = false; + if (is_background) { + if (document_type != Document::Type::General) { + LOG(ERROR) << "Receive background of type " << document_type; + document_type = Document::Type::General; + } + file_type = FileType::Background; + if (is_pattern) { + default_extension = Slice("png"); + has_png_thumbnail = true; + } else { + default_extension = Slice("jpg"); + } + } + int64 id; int64 access_hash; int32 dc_id; @@ -213,7 +228,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo if (document_type != Document::Type::VoiceNote) { for (auto &thumb : document->thumbs_) { auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", owner_dialog_id, - std::move(thumb), has_webp_thumbnail); + std::move(thumb), has_webp_thumbnail, has_png_thumbnail); if (photo_size.get_offset() == 0) { thumbnail = std::move(photo_size.get<0>()); } else { diff --git a/td/telegram/DocumentsManager.h b/td/telegram/DocumentsManager.h index 78ace1fe3..232b1d9a6 100644 --- a/td/telegram/DocumentsManager.h +++ b/td/telegram/DocumentsManager.h @@ -78,7 +78,8 @@ class DocumentsManager { Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id, MultiPromiseActor *load_data_multipromise_ptr = nullptr, - Document::Type default_document_type = Document::Type::General); + Document::Type default_document_type = Document::Type::General, bool is_background = false, + bool is_pattern = false); void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type, bool replace); diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 7c00b1cfc..51f387c08 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -7,12 +7,12 @@ #include "td/telegram/FileReferenceManager.h" #include "td/telegram/AnimationsManager.h" +#include "td/telegram/BackgroundManager.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/Global.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/StickersManager.h" -#include "td/telegram/WallpaperManager.h" #include "td/telegram/WebPagesManager.h" #include "td/utils/common.h" @@ -45,7 +45,7 @@ fileSourceUserProfilePhoto user_id:int32 photo_id:int64 = FileSource; // repair fileSourceBasicGroupPhoto basic_group_id:int32 = FileSource; // repaired with messages.getChats fileSourceSupergroupPhoto supergroup_id:int32 = FileSource; // repaired with channels.getChannels fileSourceWebPage url:string = FileSource; // repaired with messages.getWebPage -fileSourceWallpapers = FileSource; // repaired with account.getWallPapers +fileSourceWallpapers = FileSource; // can't be repaired fileSourceSavedAnimations = FileSource; // repaired with messages.getSavedGifs fileSourceRecentStickers is_attached:Bool = FileSource; // repaired with messages.getRecentStickers, not reliable fileSourceFavoriteStickers = FileSource; // repaired with messages.getFavedStickers, not reliable @@ -82,11 +82,6 @@ FileSourceId FileReferenceManager::create_channel_photo_file_source(ChannelId ch return add_file_source_id(source, PSLICE() << "photo of " << channel_id); } -FileSourceId FileReferenceManager::create_wallpapers_file_source() { - FileSourceWallpapers source; - return add_file_source_id(source, "wallpapers"); -} - FileSourceId FileReferenceManager::create_web_page_file_source(string url) { FileSourceWebPage source{std::move(url)}; auto source_str = PSTRING() << "web page of " << source.url; @@ -264,9 +259,7 @@ void FileReferenceManager::send_query(Destination dest, FileSourceId file_source send_closure_later(G()->contacts_manager(), &ContactsManager::reload_channel, source.channel_id, std::move(promise)); }, - [&](const FileSourceWallpapers &source) { - send_closure_later(G()->wallpaper_manager(), &WallpaperManager::reload_wallpapers, std::move(promise)); - }, + [&](const FileSourceWallpapers &source) { promise.set_error(Status::Error("Can't repair old wallpapers")); }, [&](const FileSourceWebPage &source) { send_closure_later(G()->web_pages_manager(), &WebPagesManager::reload_web_page_by_url, source.url, std::move(promise)); diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index af62f52a3..835b4b5ee 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -39,7 +39,7 @@ class FileReferenceManager : public Actor { 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_wallpapers_file_source(); old wallpapers can't be repaired FileSourceId create_web_page_file_source(string url); FileSourceId create_saved_animations_file_source(); FileSourceId create_recent_stickers_file_source(bool is_attached); diff --git a/td/telegram/FileReferenceManager.hpp b/td/telegram/FileReferenceManager.hpp index 97a07c965..bc914ff69 100644 --- a/td/telegram/FileReferenceManager.hpp +++ b/td/telegram/FileReferenceManager.hpp @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/AnimationsManager.h" +#include "td/telegram/BackgroundManager.h" #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" #include "td/telegram/ContactsManager.h" @@ -17,7 +18,6 @@ #include "td/telegram/StickersManager.h" #include "td/telegram/Td.h" #include "td/telegram/UserId.h" -#include "td/telegram/WallpaperManager.h" #include "td/telegram/WebPagesManager.h" #include "td/utils/common.h" @@ -73,7 +73,7 @@ FileSourceId FileReferenceManager::parse_file_source(Td *td, ParserT &parser) { return td->contacts_manager_->get_channel_photo_file_source_id(channel_id); } case 4: - return td->wallpaper_manager_->get_wallpapers_file_source_id(); + return FileSourceId(); // there is no way to repair old wallpapers case 5: { string url; td::parse(url, parser); diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 537dd5495..5448ca288 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -31,6 +31,7 @@ namespace td { class AnimationsManager; +class BackgroundManager; class CallManager; class ConfigManager; class ConfigShared; @@ -53,7 +54,6 @@ class TdDb; class TempAuthKeyWatchdog; class TopDialogManager; class UpdatesManager; -class WallpaperManager; class WebPagesManager; } // namespace td @@ -155,6 +155,13 @@ class Global : public ActorContext { animations_manager_ = animations_manager; } + ActorId background_manager() const { + return background_manager_; + } + void set_background_manager(ActorId background_manager) { + background_manager_ = background_manager; + } + ActorId call_manager() const { return call_manager_; } @@ -253,13 +260,6 @@ class Global : public ActorContext { updates_manager_ = updates_manager; } - ActorId wallpaper_manager() const { - return wallpaper_manager_; - } - void set_wallpaper_manager(ActorId wallpaper_manager) { - wallpaper_manager_ = wallpaper_manager; - } - ActorId web_pages_manager() const { return web_pages_manager_; } @@ -356,6 +356,7 @@ class Global : public ActorContext { ActorId td_; ActorId animations_manager_; + ActorId background_manager_; ActorId call_manager_; ActorId config_manager_; ActorId contacts_manager_; @@ -370,7 +371,6 @@ class Global : public ActorContext { ActorId storage_manager_; ActorId top_dialog_manager_; ActorId updates_manager_; - ActorId wallpaper_manager_; ActorId web_pages_manager_; ActorOwn connection_creator_; ActorOwn temp_auth_key_watchdog_; diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 261066aab..3da732016 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -98,7 +98,7 @@ td_api::object_ptr get_minithumbnail_object(const string static FileId register_photo(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash, std::string upload_file_reference, tl_object_ptr &&location_ptr, DialogId owner_dialog_id, - int32 file_size, bool is_webp = false) { + int32 file_size, bool is_webp = false, bool is_png = false) { DcId dc_id; int32 local_id; int64 volume_id; @@ -131,11 +131,11 @@ static FileId register_photo(FileManager *file_manager, FileType file_type, int6 break; } - LOG(DEBUG) << "Receive " << (is_webp ? "webp" : "jpeg") << " photo of type " << static_cast(file_type) - << " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: (" << id << ", " << access_hash - << ")"; + LOG(DEBUG) << "Receive " << (is_webp ? "webp" : (is_png ? "png" : "jpeg")) << " photo of type " + << static_cast(file_type) << " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: (" + << id << ", " << access_hash << ")"; auto suggested_name = PSTRING() << static_cast(volume_id) << "_" << static_cast(local_id) - << (is_webp ? ".webp" : ".jpg"); + << (is_webp ? ".webp" : (is_png ? ".png" : ".jpg")); return file_manager->register_remote(FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id, upload_file_reference, download_file_reference), FileLocationSource::FromServer, owner_dialog_id, file_size, 0, @@ -288,7 +288,8 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice Variant get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash, std::string upload_file_reference, DialogId owner_dialog_id, - tl_object_ptr &&size_ptr, bool is_webp) { + tl_object_ptr &&size_ptr, bool is_webp, + bool is_png) { tl_object_ptr location_ptr; string type; @@ -331,7 +332,7 @@ Variant get_photo_size(FileManager *file_manager, FileType fi } res.file_id = register_photo(file_manager, file_type, id, access_hash, upload_file_reference, std::move(location_ptr), - owner_dialog_id, res.size, is_webp); + owner_dialog_id, res.size, is_webp, is_png); if (!content.empty()) { file_manager->set_content(res.file_id, std::move(content)); @@ -527,7 +528,7 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr && for (auto &size_ptr : photo->sizes_) { auto photo_size = get_photo_size(file_manager, FileType::Photo, photo->id_, photo->access_hash_, - photo->file_reference_.as_slice().str(), owner_dialog_id, std::move(size_ptr), false); + photo->file_reference_.as_slice().str(), owner_dialog_id, std::move(size_ptr), false, false); if (photo_size.get_offset() == 0) { res.photos.push_back(std::move(photo_size.get<0>())); } else { diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 644904b61..a8bd4b5ca 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -88,7 +88,7 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice int32 width, int32 height); Variant get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash, std::string upload_file_reference, DialogId owner_dialog_id, - tl_object_ptr &&size_ptr, bool is_webp); + tl_object_ptr &&size_ptr, bool is_webp, bool is_png); PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id, tl_object_ptr web_document_ptr); td_api::object_ptr get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 8039fb975..4dcbacb57 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1168,7 +1168,7 @@ std::pair StickersManager::on_get_sticker_document(tl_object_ptr< PhotoSize thumbnail; for (auto &thumb : document->thumbs_) { auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", DialogId(), - std::move(thumb), has_webp_thumbnail(sticker)); + std::move(thumb), has_webp_thumbnail(sticker), false); if (photo_size.get_offset() == 0) { thumbnail = std::move(photo_size.get<0>()); break; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8e7562680..812f09912 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -10,6 +10,7 @@ #include "td/telegram/AnimationsManager.h" #include "td/telegram/AudiosManager.h" #include "td/telegram/AuthManager.h" +#include "td/telegram/BackgroundManager.h" #include "td/telegram/CallbackQueriesManager.h" #include "td/telegram/CallId.h" #include "td/telegram/CallManager.h" @@ -71,7 +72,6 @@ #include "td/telegram/VideoNotesManager.h" #include "td/telegram/VideosManager.h" #include "td/telegram/VoiceNotesManager.h" -#include "td/telegram/WallpaperManager.h" #include "td/telegram/WebPageId.h" #include "td/telegram/WebPagesManager.h" @@ -2885,17 +2885,17 @@ class GetSupportUserRequest : public RequestActor<> { } }; -class GetWallpapersRequest : public RequestOnceActor { +class GetBackgroundsRequest : public RequestOnceActor { void do_run(Promise &&promise) override { - td->wallpaper_manager_->get_wallpapers(std::move(promise)); + td->background_manager_->get_backgrounds(std::move(promise)); } void do_send_result() override { - send_result(td->wallpaper_manager_->get_wallpapers_object()); + send_result(td->background_manager_->get_backgrounds_object()); } public: - GetWallpapersRequest(ActorShared td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) { + GetBackgroundsRequest(ActorShared td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) { } }; @@ -3689,6 +3689,8 @@ void Td::dec_actor_refcnt() { LOG(DEBUG) << "AudiosManager was cleared " << timer; auth_manager_.reset(); LOG(DEBUG) << "AuthManager was cleared " << timer; + background_manager_.reset(); + LOG(DEBUG) << "BackgroundManager was cleared " << timer; contacts_manager_.reset(); LOG(DEBUG) << "ContactsManager was cleared " << timer; documents_manager_.reset(); @@ -3715,8 +3717,6 @@ void Td::dec_actor_refcnt() { LOG(DEBUG) << "VideosManager was cleared " << timer; voice_notes_manager_.reset(); LOG(DEBUG) << "VoiceNotesManager was cleared " << timer; - wallpaper_manager_.reset(); - LOG(DEBUG) << "WallpaperManager was cleared " << timer; web_pages_manager_.reset(); LOG(DEBUG) << "WebPagesManager was cleared " << timer; Promise<> promise = PromiseCreator::lambda([actor_id = create_reference()](Unit) mutable { actor_id.reset(); }); @@ -3868,6 +3868,8 @@ void Td::clear() { LOG(DEBUG) << "AnimationsManager actor was cleared " << timer; auth_manager_actor_.reset(); LOG(DEBUG) << "AuthManager actor was cleared " << timer; + background_manager_actor_.reset(); + LOG(DEBUG) << "BackgroundManager actor was cleared " << timer; contacts_manager_actor_.reset(); LOG(DEBUG) << "ContactsManager actor was cleared " << timer; file_manager_actor_.reset(); @@ -3886,8 +3888,6 @@ void Td::clear() { LOG(DEBUG) << "StickersManager actor was cleared " << timer; updates_manager_actor_.reset(); LOG(DEBUG) << "UpdatesManager actor was cleared " << timer; - wallpaper_manager_actor_.reset(); - LOG(DEBUG) << "WallpaperManager actor was cleared " << timer; web_pages_manager_actor_.reset(); LOG(DEBUG) << "WebPagesManager actor was cleared " << timer; } @@ -4247,10 +4247,6 @@ void Td::init_file_manager() { return td_->file_reference_manager_->add_file_source(file_id, file_source_id); } - FileSourceId get_wallpapers_file_source_id() final { - return td_->wallpaper_manager_->get_wallpapers_file_source_id(); - } - bool remove_file_source(FileId file_id, FileSourceId file_source_id) final { return td_->file_reference_manager_->remove_file_source(file_id, file_source_id); } @@ -4298,6 +4294,9 @@ void Td::init_managers() { animations_manager_ = make_unique(this, create_reference()); animations_manager_actor_ = register_actor("AnimationsManager", animations_manager_.get()); G()->set_animations_manager(animations_manager_actor_.get()); + background_manager_ = make_unique(this, create_reference()); + background_manager_actor_ = register_actor("BackgroundManager", background_manager_.get()); + G()->set_background_manager(background_manager_actor_.get()); contacts_manager_ = make_unique(this, create_reference()); contacts_manager_actor_ = register_actor("ContactsManager", contacts_manager_.get()); G()->set_contacts_manager(contacts_manager_actor_.get()); @@ -4317,9 +4316,6 @@ void Td::init_managers() { updates_manager_ = make_unique(this, create_reference()); updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get()); G()->set_updates_manager(updates_manager_actor_.get()); - wallpaper_manager_ = make_unique(this, create_reference()); - wallpaper_manager_actor_ = register_actor("WallpaperManager", wallpaper_manager_.get()); - G()->set_wallpaper_manager(wallpaper_manager_actor_.get()); web_pages_manager_ = make_unique(this, create_reference()); web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get()); G()->set_web_pages_manager(web_pages_manager_actor_.get()); @@ -6943,9 +6939,9 @@ void Td::on_request(uint64 id, const td_api::getSupportUser &request) { CREATE_NO_ARGS_REQUEST(GetSupportUserRequest); } -void Td::on_request(uint64 id, const td_api::getWallpapers &request) { +void Td::on_request(uint64 id, const td_api::getBackgrounds &request) { CHECK_IS_USER(); - CREATE_NO_ARGS_REQUEST(GetWallpapersRequest); + CREATE_NO_ARGS_REQUEST(GetBackgroundsRequest); } void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 86c8cd551..e85d52899 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -39,6 +39,7 @@ namespace td { class AnimationsManager; class AudiosManager; class AuthManager; +class BackgroundManager; class CallManager; class CallbackQueriesManager; class ConfigManager; @@ -66,7 +67,6 @@ class UpdatesManager; class VideoNotesManager; class VideosManager; class VoiceNotesManager; -class WallpaperManager; class WebPagesManager; } // namespace td @@ -140,6 +140,8 @@ class Td final : public NetQueryCallback { ActorOwn animations_manager_actor_; unique_ptr auth_manager_; ActorOwn auth_manager_actor_; + unique_ptr background_manager_; + ActorOwn background_manager_actor_; unique_ptr contacts_manager_; ActorOwn contacts_manager_actor_; unique_ptr file_manager_; @@ -158,8 +160,6 @@ class Td final : public NetQueryCallback { ActorOwn stickers_manager_actor_; unique_ptr updates_manager_; ActorOwn updates_manager_actor_; - unique_ptr wallpaper_manager_; - ActorOwn wallpaper_manager_actor_; unique_ptr web_pages_manager_; ActorOwn web_pages_manager_actor_; @@ -922,7 +922,7 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getSupportUser &request); - void on_request(uint64 id, const td_api::getWallpapers &request); + void on_request(uint64 id, const td_api::getBackgrounds &request); void on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request); diff --git a/td/telegram/WallpaperManager.cpp b/td/telegram/WallpaperManager.cpp deleted file mode 100644 index 8a1369172..000000000 --- a/td/telegram/WallpaperManager.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -#include "td/telegram/WallpaperManager.h" - -#include "td/telegram/td_api.h" -#include "td/telegram/telegram_api.h" - -#include "td/telegram/DialogId.h" -#include "td/telegram/FileReferenceManager.h" -#include "td/telegram/files/FileManager.h" -#include "td/telegram/files/FileType.h" -#include "td/telegram/Global.h" -#include "td/telegram/Photo.h" -#include "td/telegram/Td.h" - -#include "td/utils/buffer.h" -#include "td/utils/common.h" -#include "td/utils/misc.h" - -namespace td { - -class GetWallpapersQuery : public Td::ResultHandler { - Promise>> promise_; - - public: - explicit GetWallpapersQuery(Promise>> &&promise) - : promise_(std::move(promise)) { - } - - void send() { - send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getWallPapers(0)))); - } - - void on_result(uint64 id, BufferSlice packet) override { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(id, result_ptr.move_as_error()); - } - - // TODO - promise_.set_value(vector>()); - } - - void on_error(uint64 id, Status status) override { - promise_.set_error(std::move(status)); - } -}; - -WallpaperManager::WallpaperManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { -} - -void WallpaperManager::tear_down() { - parent_.reset(); -} - -void WallpaperManager::get_wallpapers(Promise &&promise) { - if (!wallpapers_.empty()) { - return promise.set_value(Unit()); - } - - reload_wallpapers(std::move(promise)); -} - -void WallpaperManager::reload_wallpapers(Promise &&promise) { - pending_get_wallpapers_queries_.push_back(std::move(promise)); - if (pending_get_wallpapers_queries_.size() == 1) { - auto request_promise = PromiseCreator::lambda( - [actor_id = actor_id(this)](Result>> result) { - send_closure(actor_id, &WallpaperManager::on_get_wallpapers, std::move(result)); - }); - - td_->create_handler(std::move(request_promise))->send(); - } -} - -void WallpaperManager::on_get_wallpapers(Result>> result) { - auto promises = std::move(pending_get_wallpapers_queries_); - CHECK(!promises.empty()); - reset_to_empty(pending_get_wallpapers_queries_); - - if (result.is_error()) { - // do not clear wallpapers_ - - auto error = result.move_as_error(); - for (auto &promise : promises) { - promise.set_error(error.clone()); - } - return; - } - - /* - wallpapers_ = transform(result.move_as_ok(), [file_manager = td_->file_manager_.get()]( - tl_object_ptr &&wallpaper_ptr) { - CHECK(wallpaper_ptr != nullptr); - switch (wallpaper_ptr->get_id()) { - case telegram_api::wallPaper::ID: { - auto wallpaper = move_tl_object_as(wallpaper_ptr); - vector sizes; - sizes.reserve(wallpaper->sizes_.size()); - for (auto &size : wallpaper->sizes_) { - auto photo_size = - get_photo_size(file_manager, FileType::Wallpaper, 0, 0, "", DialogId(), std::move(size), false); - if (photo_size.get_offset() == 0) { - sizes.push_back(std::move(photo_size.get<0>())); - } else { - LOG(ERROR) << "Receive minithumbnail for a wallpaper"; - } - } - return Wallpaper{wallpaper->id_, std::move(sizes), wallpaper->color_}; - } - case telegram_api::wallPaperSolid::ID: { - auto wallpaper = move_tl_object_as(wallpaper_ptr); - return Wallpaper{wallpaper->id_, {}, wallpaper->bg_color_}; - } - default: - UNREACHABLE(); - return Wallpaper{0, {}, 0}; - } - }); - */ - vector new_file_ids; - for (auto &wallpaper : wallpapers_) { - append(new_file_ids, transform(wallpaper.sizes, [](auto &size) { return size.file_id; })); - }; - td_->file_manager_->change_files_source(get_wallpapers_file_source_id(), wallpaper_file_ids_, new_file_ids); - wallpaper_file_ids_ = std::move(new_file_ids); - - for (auto &promise : promises) { - promise.set_value(Unit()); - } -} - -FileSourceId WallpaperManager::get_wallpapers_file_source_id() { - if (!wallpaper_source_id_.is_valid()) { - wallpaper_source_id_ = td_->file_reference_manager_->create_wallpapers_file_source(); - } - return 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) { - return td_api::make_object( - wallpaper.id, get_photo_sizes_object(file_manager, wallpaper.sizes), wallpaper.color); - })); -} - -} // namespace td diff --git a/td/telegram/WallpaperManager.h b/td/telegram/WallpaperManager.h deleted file mode 100644 index 33b3968d1..000000000 --- a/td/telegram/WallpaperManager.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -#pragma once - -#include "td/telegram/files/FileId.h" -#include "td/telegram/files/FileSourceId.h" -#include "td/telegram/Photo.h" -#include "td/telegram/td_api.h" -#include "td/telegram/telegram_api.h" - -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" - -#include "td/utils/common.h" -#include "td/utils/Status.h" - -namespace td { - -class Td; - -class WallpaperManager : public Actor { - public: - WallpaperManager(Td *td, ActorShared<> parent); - - void get_wallpapers(Promise &&promise); - - void reload_wallpapers(Promise &&promise); - - td_api::object_ptr get_wallpapers_object() const; - - FileSourceId get_wallpapers_file_source_id(); - - private: - void tear_down() override; - - void on_get_wallpapers(Result>> result); - - struct Wallpaper { - int32 id = 0; - vector sizes; - int32 color = 0; - - Wallpaper(int32 id, vector sizes, int32 color) : id(id), sizes(std::move(sizes)), color(color) { - } - }; - vector wallpapers_; - vector wallpaper_file_ids_; - FileSourceId wallpaper_source_id_; - - vector> pending_get_wallpapers_queries_; - - Td *td_; - ActorShared<> parent_; -}; - -} // namespace td diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 24717a268..2f11ef648 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1959,8 +1959,8 @@ class CliClient final : public Actor { send_request(td_api::make_object(to_integer(args))); } else if (op == "daw") { send_request(td_api::make_object()); - } else if (op == "gw") { - send_request(td_api::make_object()); + } else if (op == "gb") { + send_request(td_api::make_object()); } else if (op == "gccode") { send_request(td_api::make_object()); } else if (op == "git") { diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 41613cab7..c831dd17c 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -53,11 +53,17 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector(FileType::ProfilePhoto)] = true; immune_types[narrow_cast(FileType::Thumbnail)] = true; immune_types[narrow_cast(FileType::Wallpaper)] = true; + immune_types[narrow_cast(FileType::Background)] = true; } if (!parameters.file_types.empty()) { std::fill(immune_types.begin(), immune_types.end(), true); for (auto file_type : parameters.file_types) { + if (file_type == FileType::Secure) { + immune_types[narrow_cast(FileType::SecureRaw)] = false; + } else if (file_type == FileType::Background) { + immune_types[narrow_cast(FileType::Wallpaper)] = false; + } immune_types[narrow_cast(file_type)] = false; } } diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 89400fd2b..63ba32e15 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -294,6 +294,7 @@ class FullRemoteFileLocation { case FileType::VideoNote: case FileType::SecureRaw: case FileType::Secure: + case FileType::Background: return LocationType::Common; case FileType::None: case FileType::Size: diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index a32215276..1265380ad 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -708,7 +708,11 @@ FileManager::FileManager(unique_ptr context) : context_(std::move(conte #endif }; for (int32 i = 0; i < file_type_size; i++) { - auto path = get_files_dir(FileType(i)); + FileType file_type = static_cast(i); + if (file_type == FileType::SecureRaw || file_type == FileType::Background) { + continue; + } + auto path = get_files_dir(file_type); create_dir(path); } @@ -768,13 +772,18 @@ string FileManager::get_file_name(FileType file_type, Slice path) { return fix_file_extension(file_name, "audio", "mp3"); } break; + case FileType::Wallpaper: + case FileType::Background: + if (extension != "jpg" && extension != "jpeg" && extension != "png") { + return fix_file_extension(file_name, "wallpaper", "jpg"); + } + break; case FileType::Document: case FileType::Sticker: case FileType::Animation: case FileType::Encrypted: case FileType::Temp: case FileType::EncryptedThumbnail: - case FileType::Wallpaper: case FileType::Secure: case FileType::SecureRaw: break; @@ -2531,7 +2540,11 @@ void FileManager::cancel_upload(FileId file_id) { static bool is_document_type(FileType type) { return type == FileType::Document || type == FileType::Sticker || type == FileType::Audio || - type == FileType::Animation; + type == FileType::Animation || type == FileType::Background; +} + +static bool is_background_type(FileType type) { + return type == FileType::Wallpaper || type == FileType::Background; } string FileManager::get_persistent_id(const FullGenerateFileLocation &location) { @@ -2611,6 +2624,8 @@ Result FileManager::from_persistent_id_v2(Slice binary, FileType file_ty auto &real_file_type = remote_location.file_type_; if (is_document_type(real_file_type) && is_document_type(file_type)) { real_file_type = file_type; + } else if (is_background_type(real_file_type) && is_background_type(file_type)) { + real_file_type = file_type; } else if (real_file_type != file_type && file_type != FileType::Temp) { return Status::Error(10, "Type of file mismatch"); } @@ -2618,9 +2633,6 @@ Result FileManager::from_persistent_id_v2(Slice binary, FileType file_ty data.remote_ = RemoteFileLocation(std::move(remote_location)); 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()) { - add_file_source(file_id, context_->get_wallpapers_file_source_id()); - } return file_id; } @@ -2720,7 +2732,8 @@ Result FileManager::check_input_file_id(FileType type, Result re FileType real_type = file_view.get_type(); if (!is_encrypted && !is_secure) { if (real_type != type && !(real_type == FileType::Temp && file_view.has_url()) && - !(is_document_type(real_type) && is_document_type(type))) { + !(is_document_type(real_type) && is_document_type(type)) && + !(is_background_type(real_type) && is_background_type(type))) { // TODO: send encrypted file to unencrypted chat return Status::Error(6, "Type of file mismatch"); } diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 3222d2d4c..9a2271c8d 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -346,8 +346,6 @@ class FileManager : public FileLoadManager::Callback { virtual bool add_file_source(FileId file_id, FileSourceId file_source_id) = 0; - virtual FileSourceId get_wallpapers_file_source_id() = 0; - virtual bool remove_file_source(FileId file_id, FileSourceId file_source_id) = 0; virtual void on_merge_files(FileId to_file_id, FileId from_file_id) = 0; diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index 7cc069347..7933d2c3d 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -123,6 +123,8 @@ tl_object_ptr as_td_api(DialogId dialog_id, auto stats = make_tl_object(dialog_id.get(), 0, 0, Auto()); int64 secure_raw_size = 0; int32 secure_raw_cnt = 0; + int64 wallpaper_raw_size = 0; + int32 wallpaper_raw_cnt = 0; for (int32 i = 0; i < file_type_size; i++) { FileType file_type = static_cast(i); auto size = stat_by_type[i].size; @@ -133,10 +135,19 @@ tl_object_ptr as_td_api(DialogId dialog_id, secure_raw_cnt = cnt; continue; } + if (file_type == FileType::Wallpaper) { + wallpaper_raw_size = size; + wallpaper_raw_cnt = cnt; + continue; + } if (file_type == FileType::Secure) { size += secure_raw_size; cnt += secure_raw_cnt; } + if (file_type == FileType::Background) { + size += wallpaper_raw_size; + cnt += wallpaper_raw_cnt; + } if (size == 0) { continue; } diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 7fb6203ab..159514e59 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -103,7 +103,7 @@ template void scan_fs(CancellationToken &token, CallbackT &&callback) { for (int32 i = 0; i < file_type_size; i++) { auto file_type = static_cast(i); - if (file_type == FileType::SecureRaw) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { continue; } auto files_dir = get_files_dir(file_type); diff --git a/td/telegram/files/FileType.h b/td/telegram/files/FileType.h index 27270c931..d9b10c9f1 100644 --- a/td/telegram/files/FileType.h +++ b/td/telegram/files/FileType.h @@ -31,6 +31,7 @@ enum class FileType : int8 { VideoNote, SecureRaw, Secure, + Background, Size, None }; @@ -62,7 +63,7 @@ inline FileType from_td_api(const td_api::FileType &file_type) { case td_api::fileTypeSecretThumbnail::ID: return FileType::EncryptedThumbnail; case td_api::fileTypeWallpaper::ID: - return FileType::Wallpaper; + return FileType::Background; case td_api::fileTypeVideoNote::ID: return FileType::VideoNote; case td_api::fileTypeSecure::ID: @@ -110,6 +111,8 @@ inline tl_object_ptr as_td_api(FileType file_type) { case FileType::SecureRaw: UNREACHABLE(); return make_tl_object(); + case FileType::Background: + return make_tl_object(); case FileType::None: return make_tl_object(); default: @@ -154,6 +157,8 @@ inline CSlice get_file_type_name(FileType file_type) { return CSlice("passport"); case FileType::Secure: return CSlice("passport"); + case FileType::Background: + return CSlice("wallpapers"); case FileType::Size: case FileType::None: default: @@ -179,6 +184,7 @@ inline FileDirType get_file_dir_type(FileType file_type) { case FileType::EncryptedThumbnail: case FileType::Secure: case FileType::SecureRaw: + case FileType::Background: return FileDirType::Secure; default: return FileDirType::Common; diff --git a/td/telegram/net/NetStatsManager.cpp b/td/telegram/net/NetStatsManager.cpp index 6b17e25b6..22478f583 100644 --- a/td/telegram/net/NetStatsManager.cpp +++ b/td/telegram/net/NetStatsManager.cpp @@ -59,7 +59,7 @@ void NetStatsManager::init() { }; for_each_stat([&](NetStatsInfo &stat, size_t id, CSlice name, FileType file_type) { - if (file_type == FileType::SecureRaw) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { id++; } stat.key = "net_stats_" + name.str(); @@ -112,7 +112,7 @@ void NetStatsManager::get_network_stats(bool current, Promise prom entry.is_call = true; result.entries.push_back(std::move(entry)); } else if (file_type != FileType::None) { - if (file_type == FileType::SecureRaw) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { return; } @@ -192,7 +192,7 @@ void NetStatsManager::add_network_stats_impl(NetStatsInfo &info, const NetworkSt void NetStatsManager::start_up() { for_each_stat([&](NetStatsInfo &info, size_t id, CSlice name, FileType file_type) { - if (file_type == FileType::SecureRaw) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { return; } @@ -252,6 +252,7 @@ std::shared_ptr NetStatsManager::get_media_stats_callback() co std::vector> NetStatsManager::get_file_stats_callbacks() const { auto result = transform(files_stats_, [](auto &stat) { return stat.stats.get_callback(); }); result[static_cast(FileType::SecureRaw)] = result[static_cast(FileType::Secure)]; + result[static_cast(FileType::Wallpaper)] = result[static_cast(FileType::Background)]; return result; }