From a8be92146d455c438bd9a5e72b967078bd96826f Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 25 May 2023 13:57:12 +0300 Subject: [PATCH] Add class DocumentsManager::Subtype. --- td/telegram/BackgroundManager.cpp | 2 +- td/telegram/DocumentsManager.cpp | 50 ++++++++++++--------- td/telegram/DocumentsManager.h | 6 ++- td/telegram/MessageExtendedMedia.cpp | 2 +- td/telegram/NotificationSettingsManager.cpp | 2 +- td/telegram/StickersManager.cpp | 4 +- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index bc8aaeffc..b33e58b0c 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -1283,7 +1283,7 @@ std::pair BackgroundManager::on_get_background( Document document = td_->documents_manager_->on_get_document( telegram_api::move_object_as(wallpaper->document_), DialogId(), nullptr, - Document::Type::General, true, is_pattern); + Document::Type::General, is_pattern ? DocumentsManager::Subtype::Pattern : DocumentsManager::Subtype::Background); if (!document.file_id.is_valid()) { LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper); return {}; diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 93ca3b846..c1fdc9c78 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -72,8 +72,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, bool is_background, bool is_pattern, - bool is_ringtone) { + Document::Type default_document_type, Subtype document_subtype) { tl_object_ptr animated; tl_object_ptr video; tl_object_ptr audio; @@ -235,27 +234,34 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo << ", has_stickers = " << has_stickers; } - 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) { + switch (document_subtype) { + case Subtype::Background: + if (document_type != Document::Type::General) { + LOG(ERROR) << "Receive background of type " << document_type; + document_type = Document::Type::General; + } + file_type = FileType::Background; + default_extension = Slice("jpg"); + break; + case Subtype::Pattern: + if (document_type != Document::Type::General) { + LOG(ERROR) << "Receive background of type " << document_type; + document_type = Document::Type::General; + } + file_type = FileType::Background; default_extension = Slice("png"); thumbnail_format = PhotoFormat::Png; - } else { - default_extension = Slice("jpg"); - } - } - - if (is_ringtone) { - if (document_type != Document::Type::Audio) { - LOG(ERROR) << "Receive notification tone of type " << document_type; - document_type = Document::Type::Audio; - } - file_type = FileType::Ringtone; - default_extension = Slice("mp3"); + break; + case Subtype::Ringtone: + if (document_type != Document::Type::Audio) { + LOG(ERROR) << "Receive notification tone of type " << document_type; + document_type = Document::Type::Audio; + } + file_type = FileType::Ringtone; + default_extension = Slice("mp3"); + break; + default: + break; } int64 id; @@ -298,7 +304,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo access_hash = document->access_hash_; dc_id = document->dc_id_; size = document->size_; - if (is_ringtone) { + if (document_subtype == Subtype::Ringtone) { date = document->date_; } mime_type = std::move(document->mime_type_); diff --git a/td/telegram/DocumentsManager.h b/td/telegram/DocumentsManager.h index a6858626b..5175c154a 100644 --- a/td/telegram/DocumentsManager.h +++ b/td/telegram/DocumentsManager.h @@ -82,10 +82,12 @@ class DocumentsManager { tl_object_ptr get_document_object(FileId file_id, PhotoFormat thumbnail_format) const; + enum class Subtype : int32 { Background, Pattern, Ringtone, Other }; + 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, bool is_background = false, - bool is_pattern = false, bool is_ringtone = false); + Document::Type default_document_type = Document::Type::General, + Subtype document_subtype = Subtype::Other); void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type, bool replace); diff --git a/td/telegram/MessageExtendedMedia.cpp b/td/telegram/MessageExtendedMedia.cpp index b085bb02d..322ead66b 100644 --- a/td/telegram/MessageExtendedMedia.cpp +++ b/td/telegram/MessageExtendedMedia.cpp @@ -74,7 +74,7 @@ MessageExtendedMedia::MessageExtendedMedia( CHECK(document_id == telegram_api::document::ID); auto parsed_document = td->documents_manager_->on_get_document( - move_tl_object_as(document_ptr), owner_dialog_id, nullptr); + move_tl_object_as(document_ptr), owner_dialog_id); if (parsed_document.empty() || parsed_document.type != Document::Type::Video) { break; } diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index cf887acaa..e376d95e0 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -1160,7 +1160,7 @@ Result NotificationSettingsManager::get_ringtone( auto parsed_document = td_->documents_manager_->on_get_document(move_tl_object_as(ringtone), DialogId(), nullptr, - Document::Type::Audio, false, false, true); + Document::Type::Audio, DocumentsManager::Subtype::Ringtone); if (parsed_document.type != Document::Type::Audio) { return Status::Error("Receive ringtone of a wrong type"); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 36beff992..50e6f83c2 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -8399,8 +8399,8 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, bool is_url, FileType file_type = file_view.get_type(); auto expected_document_type = file_type == FileType::Sticker ? Document::Type::Sticker : Document::Type::General; - auto parsed_document = td_->documents_manager_->on_get_document( - move_tl_object_as(document_ptr), DialogId(), nullptr); + auto parsed_document = + td_->documents_manager_->on_get_document(move_tl_object_as(document_ptr), DialogId()); if (parsed_document.type != expected_document_type) { if (is_url && expected_document_type == Document::Type::General && parsed_document.type == Document::Type::Sticker) {