Add class DocumentsManager::Subtype.
This commit is contained in:
parent
54b34e9180
commit
a8be92146d
|
@ -1283,7 +1283,7 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
|
|||
|
||||
Document document = td_->documents_manager_->on_get_document(
|
||||
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()) {
|
||||
LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper);
|
||||
return {};
|
||||
|
|
|
@ -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,
|
||||
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<telegram_api::documentAttributeAnimated> animated;
|
||||
tl_object_ptr<telegram_api::documentAttributeVideo> video;
|
||||
tl_object_ptr<telegram_api::documentAttributeAudio> 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_);
|
||||
|
|
|
@ -82,10 +82,12 @@ class DocumentsManager {
|
|||
|
||||
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,
|
||||
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);
|
||||
|
|
|
@ -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<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) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1160,7 +1160,7 @@ Result<FileId> NotificationSettingsManager::get_ringtone(
|
|||
|
||||
auto parsed_document =
|
||||
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) {
|
||||
return Status::Error("Receive ringtone of a wrong type");
|
||||
}
|
||||
|
|
|
@ -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<telegram_api::document>(document_ptr), DialogId(), nullptr);
|
||||
auto parsed_document =
|
||||
td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user