Move FileType to FileType.h.

GitOrigin-RevId: 7e35c0f30b7755755b0583704dcfe344cc28d117
This commit is contained in:
levlam 2019-01-20 00:54:29 +03:00
parent 3c46828749
commit e5400074ce
33 changed files with 206 additions and 161 deletions

View File

@ -501,6 +501,7 @@ set(TDLIB_SOURCE
td/telegram/files/FileLoadManager.h
td/telegram/files/FileLocation.h
td/telegram/files/FileManager.h
td/telegram/files/FileType.h
td/telegram/files/FileSourceId.h
td/telegram/files/FileStats.h
td/telegram/files/FileStatsWorker.h

View File

@ -10,6 +10,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/misc.h"

View File

@ -13,6 +13,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/InlineQueriesManager.h"
#include "td/telegram/logevent/LogEvent.h"

View File

@ -9,7 +9,9 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/StickersManager.h"

View File

@ -19,6 +19,7 @@
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Game.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputMessageText.h"

View File

@ -20,7 +20,9 @@
#include "td/telegram/DocumentsManager.hpp"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Game.h"
#include "td/telegram/Game.hpp"
#include "td/telegram/Global.h"

View File

@ -15,7 +15,9 @@
#include "td/telegram/DraftMessage.hpp"
#include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InlineQueriesManager.h"

View File

@ -10,6 +10,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/net/DcId.h"

View File

@ -8,7 +8,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/SecretInputMedia.h"
#include "td/utils/buffer.h"

View File

@ -10,6 +10,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/NetQueryDispatcher.h"

View File

@ -8,7 +8,9 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"

View File

@ -16,7 +16,9 @@
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessagesManager.h"

View File

@ -6,16 +6,6 @@
//
#include "td/telegram/Td.h"
#include "td/telegram/net/ConnectionCreator.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/MtprotoHeader.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/net/NetQueryDelayer.h"
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/net/NetStatsManager.h"
#include "td/telegram/net/NetType.h"
#include "td/telegram/net/TempAuthKeyWatchdog.h"
#include "td/telegram/AccessRights.h"
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
@ -36,6 +26,7 @@
#include "td/telegram/files/FileGcParameters.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InlineQueriesManager.h"
@ -46,6 +37,15 @@
#include "td/telegram/MessageId.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/ConnectionCreator.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/MtprotoHeader.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/net/NetQueryDelayer.h"
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/net/NetStatsManager.h"
#include "td/telegram/net/NetType.h"
#include "td/telegram/net/TempAuthKeyWatchdog.h"
#include "td/telegram/NotificationGroupId.h"
#include "td/telegram/NotificationId.h"
#include "td/telegram/NotificationManager.h"

View File

@ -10,6 +10,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/Photo.h"
#include "td/telegram/Td.h"

View File

@ -8,7 +8,6 @@
#include "td/telegram/files/FileData.h"
#include "td/telegram/files/FileDbId.h"
#include "td/telegram/files/FileLocation.h"
#include "td/actor/PromiseFuture.h"

View File

@ -9,6 +9,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/files/FileLoaderUtils.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/SecureStorage.h"

View File

@ -10,6 +10,7 @@
#include "td/telegram/files/FileLoader.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"

View File

@ -7,7 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"

View File

@ -7,6 +7,8 @@
#include "td/telegram/files/FileGcWorker.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/utils/format.h"

View File

@ -10,7 +10,6 @@
#include "td/actor/PromiseFuture.h"
#include "td/telegram/files/FileGcParameters.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileStats.h"
#include "td/utils/logging.h"

View File

@ -12,6 +12,7 @@
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileLoaderUtils.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/net/NetQueryDispatcher.h"

View File

@ -8,6 +8,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/NetQueryDispatcher.h"

View File

@ -14,6 +14,7 @@
#include "td/telegram/files/FileFromBytes.h"
#include "td/telegram/files/FileHashUploader.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/files/FileUploader.h"
#include "td/telegram/files/ResourceManager.h"
#include "td/telegram/net/DcId.h"

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/ResourceState.h"
#include "td/telegram/net/NetQuery.h"

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"

View File

@ -11,6 +11,7 @@
#include "td/telegram/files/FileBitmask.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/net/DcId.h"
#include "td/utils/base64.h"
@ -27,151 +28,6 @@
namespace td {
enum class FileType : int8 {
Thumbnail,
ProfilePhoto,
Photo,
VoiceNote,
Video,
Document,
Encrypted,
Temp,
Sticker,
Audio,
Animation,
EncryptedThumbnail,
Wallpaper,
VideoNote,
SecureRaw,
Secure,
Size,
None
};
inline FileType from_td_api(const td_api::FileType &file_type) {
switch (file_type.get_id()) {
case td_api::fileTypeThumbnail::ID:
return FileType::Thumbnail;
case td_api::fileTypeProfilePhoto::ID:
return FileType::ProfilePhoto;
case td_api::fileTypePhoto::ID:
return FileType::Photo;
case td_api::fileTypeVoiceNote::ID:
return FileType::VoiceNote;
case td_api::fileTypeVideo::ID:
return FileType::Video;
case td_api::fileTypeDocument::ID:
return FileType::Document;
case td_api::fileTypeSecret::ID:
return FileType::Encrypted;
case td_api::fileTypeUnknown::ID:
return FileType::Temp;
case td_api::fileTypeSticker::ID:
return FileType::Sticker;
case td_api::fileTypeAudio::ID:
return FileType::Audio;
case td_api::fileTypeAnimation::ID:
return FileType::Animation;
case td_api::fileTypeSecretThumbnail::ID:
return FileType::EncryptedThumbnail;
case td_api::fileTypeWallpaper::ID:
return FileType::Wallpaper;
case td_api::fileTypeVideoNote::ID:
return FileType::VideoNote;
case td_api::fileTypeSecure::ID:
return FileType::Secure;
case td_api::fileTypeNone::ID:
return FileType::None;
default:
UNREACHABLE();
return FileType::None;
}
}
inline tl_object_ptr<td_api::FileType> as_td_api(FileType file_type) {
switch (file_type) {
case FileType::Thumbnail:
return make_tl_object<td_api::fileTypeThumbnail>();
case FileType::ProfilePhoto:
return make_tl_object<td_api::fileTypeProfilePhoto>();
case FileType::Photo:
return make_tl_object<td_api::fileTypePhoto>();
case FileType::VoiceNote:
return make_tl_object<td_api::fileTypeVoiceNote>();
case FileType::Video:
return make_tl_object<td_api::fileTypeVideo>();
case FileType::Document:
return make_tl_object<td_api::fileTypeDocument>();
case FileType::Encrypted:
return make_tl_object<td_api::fileTypeSecret>();
case FileType::Temp:
return make_tl_object<td_api::fileTypeUnknown>();
case FileType::Sticker:
return make_tl_object<td_api::fileTypeSticker>();
case FileType::Audio:
return make_tl_object<td_api::fileTypeAudio>();
case FileType::Animation:
return make_tl_object<td_api::fileTypeAnimation>();
case FileType::EncryptedThumbnail:
return make_tl_object<td_api::fileTypeSecretThumbnail>();
case FileType::Wallpaper:
return make_tl_object<td_api::fileTypeWallpaper>();
case FileType::VideoNote:
return make_tl_object<td_api::fileTypeVideoNote>();
case FileType::Secure:
return make_tl_object<td_api::fileTypeSecure>();
case FileType::SecureRaw:
UNREACHABLE();
return make_tl_object<td_api::fileTypeSecure>();
case FileType::None:
return make_tl_object<td_api::fileTypeNone>();
default:
UNREACHABLE();
return nullptr;
}
}
constexpr int32 file_type_size = static_cast<int32>(FileType::Size);
extern const char *file_type_name[file_type_size];
inline StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) {
return string_builder << file_type_name[static_cast<int32>(file_type)];
}
enum class FileDirType : int8 { Secure, Common };
inline FileDirType get_file_dir_type(FileType file_type) {
switch (file_type) {
case FileType::Thumbnail:
case FileType::ProfilePhoto:
case FileType::Encrypted:
case FileType::Sticker:
case FileType::Temp:
case FileType::Wallpaper:
case FileType::EncryptedThumbnail:
case FileType::Secure:
case FileType::SecureRaw:
return FileDirType::Secure;
default:
return FileDirType::Common;
}
}
inline bool is_file_big(FileType file_type, int64 expected_size) {
switch (file_type) {
case FileType::Thumbnail:
case FileType::ProfilePhoto:
case FileType::Photo:
case FileType::EncryptedThumbnail:
return false;
default:
break;
}
constexpr int64 SMALL_FILE_MAX_SIZE = 10 << 20;
return expected_size > SMALL_FILE_MAX_SIZE;
}
struct EmptyRemoteFileLocation {
template <class StorerT>
void store(StorerT &storer) const {

View File

@ -18,6 +18,7 @@
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/files/FileStats.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Location.h"
#include "td/actor/actor.h"

View File

@ -9,6 +9,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Version.h"
#include "td/utils/logging.h"

View File

@ -7,7 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"

View File

@ -10,6 +10,8 @@
#include "td/telegram/files/FileData.h"
#include "td/telegram/files/FileDb.h"
#include "td/telegram/files/FileLoaderUtils.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/TdDb.h"

View File

@ -0,0 +1,160 @@
//
// 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/td_api.h"
#include "td/utils/logging.h"
namespace td {
enum class FileType : int8 {
Thumbnail,
ProfilePhoto,
Photo,
VoiceNote,
Video,
Document,
Encrypted,
Temp,
Sticker,
Audio,
Animation,
EncryptedThumbnail,
Wallpaper,
VideoNote,
SecureRaw,
Secure,
Size,
None
};
inline FileType from_td_api(const td_api::FileType &file_type) {
switch (file_type.get_id()) {
case td_api::fileTypeThumbnail::ID:
return FileType::Thumbnail;
case td_api::fileTypeProfilePhoto::ID:
return FileType::ProfilePhoto;
case td_api::fileTypePhoto::ID:
return FileType::Photo;
case td_api::fileTypeVoiceNote::ID:
return FileType::VoiceNote;
case td_api::fileTypeVideo::ID:
return FileType::Video;
case td_api::fileTypeDocument::ID:
return FileType::Document;
case td_api::fileTypeSecret::ID:
return FileType::Encrypted;
case td_api::fileTypeUnknown::ID:
return FileType::Temp;
case td_api::fileTypeSticker::ID:
return FileType::Sticker;
case td_api::fileTypeAudio::ID:
return FileType::Audio;
case td_api::fileTypeAnimation::ID:
return FileType::Animation;
case td_api::fileTypeSecretThumbnail::ID:
return FileType::EncryptedThumbnail;
case td_api::fileTypeWallpaper::ID:
return FileType::Wallpaper;
case td_api::fileTypeVideoNote::ID:
return FileType::VideoNote;
case td_api::fileTypeSecure::ID:
return FileType::Secure;
case td_api::fileTypeNone::ID:
return FileType::None;
default:
UNREACHABLE();
return FileType::None;
}
}
inline tl_object_ptr<td_api::FileType> as_td_api(FileType file_type) {
switch (file_type) {
case FileType::Thumbnail:
return make_tl_object<td_api::fileTypeThumbnail>();
case FileType::ProfilePhoto:
return make_tl_object<td_api::fileTypeProfilePhoto>();
case FileType::Photo:
return make_tl_object<td_api::fileTypePhoto>();
case FileType::VoiceNote:
return make_tl_object<td_api::fileTypeVoiceNote>();
case FileType::Video:
return make_tl_object<td_api::fileTypeVideo>();
case FileType::Document:
return make_tl_object<td_api::fileTypeDocument>();
case FileType::Encrypted:
return make_tl_object<td_api::fileTypeSecret>();
case FileType::Temp:
return make_tl_object<td_api::fileTypeUnknown>();
case FileType::Sticker:
return make_tl_object<td_api::fileTypeSticker>();
case FileType::Audio:
return make_tl_object<td_api::fileTypeAudio>();
case FileType::Animation:
return make_tl_object<td_api::fileTypeAnimation>();
case FileType::EncryptedThumbnail:
return make_tl_object<td_api::fileTypeSecretThumbnail>();
case FileType::Wallpaper:
return make_tl_object<td_api::fileTypeWallpaper>();
case FileType::VideoNote:
return make_tl_object<td_api::fileTypeVideoNote>();
case FileType::Secure:
return make_tl_object<td_api::fileTypeSecure>();
case FileType::SecureRaw:
UNREACHABLE();
return make_tl_object<td_api::fileTypeSecure>();
case FileType::None:
return make_tl_object<td_api::fileTypeNone>();
default:
UNREACHABLE();
return nullptr;
}
}
constexpr int32 file_type_size = static_cast<int32>(FileType::Size);
extern const char *file_type_name[file_type_size];
inline StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) {
return string_builder << file_type_name[static_cast<int32>(file_type)];
}
enum class FileDirType : int8 { Secure, Common };
inline FileDirType get_file_dir_type(FileType file_type) {
switch (file_type) {
case FileType::Thumbnail:
case FileType::ProfilePhoto:
case FileType::Encrypted:
case FileType::Sticker:
case FileType::Temp:
case FileType::Wallpaper:
case FileType::EncryptedThumbnail:
case FileType::Secure:
case FileType::SecureRaw:
return FileDirType::Secure;
default:
return FileDirType::Common;
}
}
inline bool is_file_big(FileType file_type, int64 expected_size) {
switch (file_type) {
case FileType::Thumbnail:
case FileType::ProfilePhoto:
case FileType::Photo:
case FileType::EncryptedThumbnail:
return false;
default:
break;
}
constexpr int64 SMALL_FILE_MAX_SIZE = 10 << 20;
return expected_size > SMALL_FILE_MAX_SIZE;
}
} // namespace td

View File

@ -9,6 +9,7 @@
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLoader.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/utils/port/FileFd.h"
#include "td/utils/Status.h"

View File

@ -11,7 +11,7 @@
#include "td/telegram/td_api.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/net/NetType.h"
#include "td/net/NetStats.h"