diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 37daed2e6..6cb661572 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -297,15 +297,15 @@ Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr &&photo, DialogId owner_dialog_id) { +Photo get_photo(Td *td, tl_object_ptr &&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(photo), owner_dialog_id); + return get_photo(td, move_tl_object_as(photo), owner_dialog_id, file_type); } -Photo get_photo(Td *td, tl_object_ptr &&photo, DialogId owner_dialog_id) { +Photo get_photo(Td *td, tl_object_ptr &&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 &&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 &&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; diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 5b3df191b..d5db21063 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -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 &&photo, DialogId owner_dialog_id); +Photo get_photo(Td *td, tl_object_ptr &&photo, DialogId owner_dialog_id, + FileType file_type = FileType::Photo); -Photo get_photo(Td *td, tl_object_ptr &&photo, DialogId owner_dialog_id); +Photo get_photo(Td *td, tl_object_ptr &&photo, DialogId owner_dialog_id, + FileType file_type = FileType::Photo); Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr &&file, tl_object_ptr &&photo, DialogId owner_dialog_id); diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index a8a5cc059..db9503194 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -73,7 +73,7 @@ unique_ptr get_story_content(Td *td, tl_object_ptrphoto_), 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> get_input_story_content( auto input_story = static_cast(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, diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index c307dc454..9a8c19d76 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -395,6 +395,7 @@ class FullRemoteFileLocation { auto &thumbnail = source.thumbnail(); switch (thumbnail.file_type) { case FileType::Photo: + case FileType::PhotoStory: return make_tl_object( id, access_hash, BufferSlice(file_reference_), std::string(1, static_cast(static_cast(thumbnail.thumbnail_type)))); diff --git a/td/telegram/files/FileLocation.hpp b/td/telegram/files/FileLocation.hpp index 5c8cf53e8..3565905bb 100644 --- a/td/telegram/files/FileLocation.hpp +++ b/td/telegram/files/FileLocation.hpp @@ -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; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 864fb4da4..62a19c2fc 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -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"); diff --git a/td/telegram/files/FileType.cpp b/td/telegram/files/FileType.cpp index 0ea10e952..91f5c70ca 100644 --- a/td/telegram/files/FileType.cpp +++ b/td/telegram/files/FileType.cpp @@ -93,6 +93,8 @@ tl_object_ptr get_file_type_object(FileType file_type) { return make_tl_object(); case FileType::CallLog: return make_tl_object(); + case FileType::PhotoStory: + return make_tl_object(); case FileType::None: return make_tl_object(); 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; diff --git a/td/telegram/files/FileType.h b/td/telegram/files/FileType.h index 91c945800..07a523e6e 100644 --- a/td/telegram/files/FileType.h +++ b/td/telegram/files/FileType.h @@ -35,6 +35,7 @@ enum class FileType : int32 { DocumentAsFile, Ringtone, CallLog, + PhotoStory, Size, None };