Add FileType::PhotoStory.

This commit is contained in:
levlam 2023-05-25 01:26:26 +03:00
parent d2ef7d67a7
commit b88312dda1
8 changed files with 29 additions and 11 deletions

View File

@ -297,15 +297,15 @@ Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFi
return res;
}
Photo get_photo(Td *td, tl_object_ptr<telegram_api::Photo> &&photo, DialogId owner_dialog_id) {
Photo get_photo(Td *td, tl_object_ptr<telegram_api::Photo> &&photo, DialogId owner_dialog_id, FileType file_type) {
if (photo == nullptr || photo->get_id() == telegram_api::photoEmpty::ID) {
return Photo();
}
CHECK(photo->get_id() == telegram_api::photo::ID);
return get_photo(td, move_tl_object_as<telegram_api::photo>(photo), owner_dialog_id);
return get_photo(td, move_tl_object_as<telegram_api::photo>(photo), owner_dialog_id, file_type);
}
Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId owner_dialog_id) {
Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId owner_dialog_id, FileType file_type) {
CHECK(photo != nullptr);
Photo res;
@ -320,8 +320,8 @@ Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId own
DcId dc_id = DcId::create(photo->dc_id_);
for (auto &size_ptr : photo->sizes_) {
auto photo_size = get_photo_size(td->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Photo, 0),
photo->id_, photo->access_hash_, photo->file_reference_.as_slice().str(), dc_id,
auto photo_size = get_photo_size(td->file_manager_.get(), PhotoSizeSource::thumbnail(file_type, 0), photo->id_,
photo->access_hash_, photo->file_reference_.as_slice().str(), dc_id,
owner_dialog_id, std::move(size_ptr), PhotoFormat::Jpeg);
if (photo_size.get_offset() == 0) {
PhotoSize &size = photo_size.get<0>();
@ -338,7 +338,7 @@ Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId own
for (auto &size_ptr : photo->video_sizes_) {
auto animation =
process_video_size(td, PhotoSizeSource::thumbnail(FileType::Photo, 0), photo->id_, photo->access_hash_,
process_video_size(td, PhotoSizeSource::thumbnail(file_type, 0), photo->id_, photo->access_hash_,
photo->file_reference_.as_slice().str(), dc_id, owner_dialog_id, std::move(size_ptr));
if (animation.empty()) {
continue;

View File

@ -105,9 +105,11 @@ bool need_update_dialog_photo(const DialogPhoto &from, const DialogPhoto &to);
StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo);
Photo get_photo(Td *td, tl_object_ptr<telegram_api::Photo> &&photo, DialogId owner_dialog_id);
Photo get_photo(Td *td, tl_object_ptr<telegram_api::Photo> &&photo, DialogId owner_dialog_id,
FileType file_type = FileType::Photo);
Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId owner_dialog_id);
Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId owner_dialog_id,
FileType file_type = FileType::Photo);
Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFile> &&file,
tl_object_ptr<secret_api::decryptedMessageMediaPhoto> &&photo, DialogId owner_dialog_id);

View File

@ -73,7 +73,7 @@ unique_ptr<StoryContent> get_story_content(Td *td, tl_object_ptr<telegram_api::M
break;
}
auto photo = get_photo(td, std::move(media->photo_), owner_dialog_id);
auto photo = get_photo(td, std::move(media->photo_), owner_dialog_id, FileType::PhotoStory);
if (photo.is_empty()) {
LOG(ERROR) << "Receive a story with empty photo";
break;
@ -140,6 +140,8 @@ Result<unique_ptr<StoryContent>> get_input_story_content(
auto input_story = static_cast<const td_api::inputStoryContentPhoto *>(input_story_content.get());
TRY_RESULT(file_id, td->file_manager_->get_input_file_id(FileType::Photo, input_story->photo_, owner_dialog_id,
false, false));
file_id =
td->file_manager_->copy_file_id(file_id, FileType::PhotoStory, owner_dialog_id, "get_input_story_content");
auto sticker_file_ids =
td->stickers_manager_->get_attached_sticker_file_ids(input_story->added_sticker_file_ids_);
TRY_RESULT(photo,

View File

@ -395,6 +395,7 @@ class FullRemoteFileLocation {
auto &thumbnail = source.thumbnail();
switch (thumbnail.file_type) {
case FileType::Photo:
case FileType::PhotoStory:
return make_tl_object<telegram_api::inputPhotoFileLocation>(
id, access_hash, BufferSlice(file_reference_),
std::string(1, static_cast<char>(static_cast<uint8>(thumbnail.thumbnail_type))));

View File

@ -237,8 +237,8 @@ void FullRemoteFileLocation::parse(ParserT &parser) {
break;
case PhotoSizeSource::Type::Thumbnail:
if (photo().source_.get_file_type("FullRemoteFileLocation::parse") != file_type_ ||
(file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail &&
file_type_ != FileType::EncryptedThumbnail)) {
(file_type_ != FileType::Photo && file_type_ != FileType::PhotoStory &&
file_type_ != FileType::Thumbnail && file_type_ != FileType::EncryptedThumbnail)) {
parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail");
}
break;

View File

@ -867,6 +867,7 @@ string FileManager::get_file_name(FileType file_type, Slice path) {
break;
case FileType::ProfilePhoto:
case FileType::Photo:
case FileType::PhotoStory:
if (extension != "jpg" && extension != "jpeg" && extension != "gif" && extension != "png" && extension != "tif" &&
extension != "bmp") {
return fix_file_extension(file_name, "photo", "jpg");

View File

@ -93,6 +93,8 @@ tl_object_ptr<td_api::FileType> get_file_type_object(FileType file_type) {
return make_tl_object<td_api::fileTypeNotificationSound>();
case FileType::CallLog:
return make_tl_object<td_api::fileTypeDocument>();
case FileType::PhotoStory:
return make_tl_object<td_api::fileTypePhoto>();
case FileType::None:
return make_tl_object<td_api::fileTypeNone>();
default:
@ -111,6 +113,8 @@ FileType get_main_file_type(FileType file_type) {
return FileType::Document;
case FileType::CallLog:
return FileType::Document;
case FileType::PhotoStory:
return FileType::Photo;
default:
return file_type;
}
@ -150,6 +154,8 @@ CSlice get_file_type_name(FileType file_type) {
return CSlice("wallpapers");
case FileType::Ringtone:
return CSlice("notification_sounds");
case FileType::PhotoStory:
return CSlice("stories");
default:
UNREACHABLE();
return CSlice("none");
@ -163,6 +169,7 @@ FileTypeClass get_file_type_class(FileType file_type) {
case FileType::Thumbnail:
case FileType::EncryptedThumbnail:
case FileType::Wallpaper:
case FileType::PhotoStory:
return FileTypeClass::Photo;
case FileType::Video:
case FileType::VoiceNote:
@ -237,6 +244,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) {
return string_builder << "NotificationSound";
case FileType::CallLog:
return string_builder << "CallLog";
case FileType::PhotoStory:
return string_builder << "PhotoStory";
case FileType::Size:
case FileType::None:
default:
@ -257,6 +266,7 @@ FileDirType get_file_dir_type(FileType file_type) {
case FileType::SecureDecrypted:
case FileType::Background:
case FileType::Ringtone:
case FileType::PhotoStory:
return FileDirType::Secure;
default:
return FileDirType::Common;
@ -286,6 +296,7 @@ bool can_reuse_remote_file(FileType file_type) {
case FileType::EncryptedThumbnail:
case FileType::Background:
case FileType::CallLog:
case FileType::PhotoStory:
return false;
default:
return true;

View File

@ -35,6 +35,7 @@ enum class FileType : int32 {
DocumentAsFile,
Ringtone,
CallLog,
PhotoStory,
Size,
None
};