Add and use get_file_type_class.

This commit is contained in:
levlam 2022-04-21 22:14:12 +03:00
parent 7fcd92a622
commit f6fd1f55cb
4 changed files with 42 additions and 63 deletions

View File

@ -192,32 +192,17 @@ class FullRemoteFileLocation {
if (is_web()) {
return LocationType::Web;
}
switch (file_type_) {
case FileType::Photo:
case FileType::ProfilePhoto:
case FileType::Thumbnail:
case FileType::EncryptedThumbnail:
case FileType::Wallpaper:
switch (get_file_type_class(file_type_)) {
case FileTypeClass::Photo:
return LocationType::Photo;
case FileType::Video:
case FileType::VoiceNote:
case FileType::Document:
case FileType::Sticker:
case FileType::Audio:
case FileType::Animation:
case FileType::Encrypted:
case FileType::VideoNote:
case FileType::SecureRaw:
case FileType::Secure:
case FileType::Background:
case FileType::DocumentAsFile:
case FileType::Ringtone:
case FileTypeClass::Document:
case FileTypeClass::Secure:
case FileTypeClass::Encrypted:
return LocationType::Common;
case FileType::None:
case FileType::Size:
case FileTypeClass::Temp:
return LocationType::None;
default:
UNREACHABLE();
case FileType::Temp:
return LocationType::None;
}
}

View File

@ -289,37 +289,7 @@ void FullRemoteFileLocation::AsUnique::store(StorerT &storer) const {
if (key->is_web()) {
return 0;
}
switch (key->file_type_) {
case FileType::Photo:
case FileType::ProfilePhoto:
case FileType::Thumbnail:
case FileType::EncryptedThumbnail:
case FileType::Wallpaper:
return 1;
case FileType::Video:
case FileType::VoiceNote:
case FileType::Document:
case FileType::Sticker:
case FileType::Audio:
case FileType::Animation:
case FileType::VideoNote:
case FileType::Background:
case FileType::DocumentAsFile:
case FileType::Ringtone:
return 2;
case FileType::SecureRaw:
case FileType::Secure:
return 3;
case FileType::Encrypted:
return 4;
case FileType::Temp:
return 5;
case FileType::None:
case FileType::Size:
default:
UNREACHABLE();
return -1;
}
return static_cast<int32>(get_file_type_class(key->file_type_)) + 1;
}();
store(type, storer);
key.variant_.visit([&](auto &&value) {

View File

@ -160,24 +160,44 @@ CSlice get_file_type_name(FileType file_type) {
}
}
bool is_document_file_type(FileType file_type) {
FileTypeClass get_file_type_class(FileType file_type) {
switch (file_type) {
case FileType::Animation:
case FileType::Audio:
case FileType::Background:
case FileType::Photo:
case FileType::ProfilePhoto:
case FileType::Thumbnail:
case FileType::EncryptedThumbnail:
case FileType::Wallpaper:
return FileTypeClass::Photo;
case FileType::Video:
case FileType::VoiceNote:
case FileType::Document:
case FileType::Sticker:
case FileType::Audio:
case FileType::Animation:
case FileType::VideoNote:
case FileType::Background:
case FileType::DocumentAsFile:
case FileType::Ringtone:
case FileType::Sticker:
case FileType::Video:
case FileType::VideoNote:
case FileType::VoiceNote:
return true;
return FileTypeClass::Document;
case FileType::SecureRaw:
case FileType::Secure:
return FileTypeClass::Secure;
case FileType::Encrypted:
return FileTypeClass::Encrypted;
case FileType::Temp:
return FileTypeClass::Temp;
case FileType::None:
case FileType::Size:
default:
return false;
UNREACHABLE();
return FileTypeClass::Temp;
}
}
bool is_document_file_type(FileType file_type) {
return get_file_type_class(file_type) == FileTypeClass::Document;
}
StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) {
return string_builder << get_file_type_name(file_type);
}

View File

@ -50,6 +50,10 @@ FileType get_main_file_type(FileType file_type);
CSlice get_file_type_name(FileType file_type);
enum class FileTypeClass : int32 { Photo, Document, Secure, Encrypted, Temp };
FileTypeClass get_file_type_class(FileType file_type);
bool is_document_file_type(FileType file_type);
StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type);