Add class DocumentsManager::Subtype.

This commit is contained in:
levlam 2023-05-25 13:57:12 +03:00
parent 54b34e9180
commit a8be92146d
6 changed files with 37 additions and 29 deletions

View File

@ -1283,7 +1283,7 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
Document document = td_->documents_manager_->on_get_document( Document document = td_->documents_manager_->on_get_document(
telegram_api::move_object_as<telegram_api::document>(wallpaper->document_), DialogId(), nullptr, telegram_api::move_object_as<telegram_api::document>(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()) { if (!document.file_id.is_valid()) {
LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper); LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper);
return {}; return {};

View File

@ -72,8 +72,7 @@ tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId fil
Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id, Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
MultiPromiseActor *load_data_multipromise_ptr, MultiPromiseActor *load_data_multipromise_ptr,
Document::Type default_document_type, bool is_background, bool is_pattern, Document::Type default_document_type, Subtype document_subtype) {
bool is_ringtone) {
tl_object_ptr<telegram_api::documentAttributeAnimated> animated; tl_object_ptr<telegram_api::documentAttributeAnimated> animated;
tl_object_ptr<telegram_api::documentAttributeVideo> video; tl_object_ptr<telegram_api::documentAttributeVideo> video;
tl_object_ptr<telegram_api::documentAttributeAudio> audio; tl_object_ptr<telegram_api::documentAttributeAudio> audio;
@ -235,27 +234,34 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
<< ", has_stickers = " << has_stickers; << ", has_stickers = " << has_stickers;
} }
if (is_background) { switch (document_subtype) {
if (document_type != Document::Type::General) { case Subtype::Background:
LOG(ERROR) << "Receive background of type " << document_type; if (document_type != Document::Type::General) {
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) { 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"); default_extension = Slice("png");
thumbnail_format = PhotoFormat::Png; thumbnail_format = PhotoFormat::Png;
} else { break;
default_extension = Slice("jpg"); case Subtype::Ringtone:
} if (document_type != Document::Type::Audio) {
} LOG(ERROR) << "Receive notification tone of type " << document_type;
document_type = Document::Type::Audio;
if (is_ringtone) { }
if (document_type != Document::Type::Audio) { file_type = FileType::Ringtone;
LOG(ERROR) << "Receive notification tone of type " << document_type; default_extension = Slice("mp3");
document_type = Document::Type::Audio; break;
} default:
file_type = FileType::Ringtone; break;
default_extension = Slice("mp3");
} }
int64 id; int64 id;
@ -298,7 +304,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
access_hash = document->access_hash_; access_hash = document->access_hash_;
dc_id = document->dc_id_; dc_id = document->dc_id_;
size = document->size_; size = document->size_;
if (is_ringtone) { if (document_subtype == Subtype::Ringtone) {
date = document->date_; date = document->date_;
} }
mime_type = std::move(document->mime_type_); mime_type = std::move(document->mime_type_);

View File

@ -82,10 +82,12 @@ class DocumentsManager {
tl_object_ptr<td_api::document> get_document_object(FileId file_id, PhotoFormat thumbnail_format) const; tl_object_ptr<td_api::document> 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, Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
MultiPromiseActor *load_data_multipromise_ptr = nullptr, MultiPromiseActor *load_data_multipromise_ptr = nullptr,
Document::Type default_document_type = Document::Type::General, bool is_background = false, Document::Type default_document_type = Document::Type::General,
bool is_pattern = false, bool is_ringtone = false); Subtype document_subtype = Subtype::Other);
void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type, void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type,
bool replace); bool replace);

View File

@ -74,7 +74,7 @@ MessageExtendedMedia::MessageExtendedMedia(
CHECK(document_id == telegram_api::document::ID); CHECK(document_id == telegram_api::document::ID);
auto parsed_document = td->documents_manager_->on_get_document( auto parsed_document = td->documents_manager_->on_get_document(
move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id, nullptr); move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id);
if (parsed_document.empty() || parsed_document.type != Document::Type::Video) { if (parsed_document.empty() || parsed_document.type != Document::Type::Video) {
break; break;
} }

View File

@ -1160,7 +1160,7 @@ Result<FileId> NotificationSettingsManager::get_ringtone(
auto parsed_document = auto parsed_document =
td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(ringtone), DialogId(), nullptr, td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(ringtone), DialogId(), nullptr,
Document::Type::Audio, false, false, true); Document::Type::Audio, DocumentsManager::Subtype::Ringtone);
if (parsed_document.type != Document::Type::Audio) { if (parsed_document.type != Document::Type::Audio) {
return Status::Error("Receive ringtone of a wrong type"); return Status::Error("Receive ringtone of a wrong type");
} }

View File

@ -8399,8 +8399,8 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, bool is_url,
FileType file_type = file_view.get_type(); FileType file_type = file_view.get_type();
auto expected_document_type = file_type == FileType::Sticker ? Document::Type::Sticker : Document::Type::General; auto expected_document_type = file_type == FileType::Sticker ? Document::Type::Sticker : Document::Type::General;
auto parsed_document = td_->documents_manager_->on_get_document( auto parsed_document =
move_tl_object_as<telegram_api::document>(document_ptr), DialogId(), nullptr); td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(document_ptr), DialogId());
if (parsed_document.type != expected_document_type) { if (parsed_document.type != expected_document_type) {
if (is_url && expected_document_type == Document::Type::General && if (is_url && expected_document_type == Document::Type::General &&
parsed_document.type == Document::Type::Sticker) { parsed_document.type == Document::Type::Sticker) {