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; 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) { if (photo == nullptr || photo->get_id() == telegram_api::photoEmpty::ID) {
return Photo(); return Photo();
} }
CHECK(photo->get_id() == telegram_api::photo::ID); 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); CHECK(photo != nullptr);
Photo res; 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_); DcId dc_id = DcId::create(photo->dc_id_);
for (auto &size_ptr : photo->sizes_) { for (auto &size_ptr : photo->sizes_) {
auto photo_size = get_photo_size(td->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Photo, 0), auto photo_size = get_photo_size(td->file_manager_.get(), PhotoSizeSource::thumbnail(file_type, 0), photo->id_,
photo->id_, photo->access_hash_, photo->file_reference_.as_slice().str(), dc_id, photo->access_hash_, photo->file_reference_.as_slice().str(), dc_id,
owner_dialog_id, std::move(size_ptr), PhotoFormat::Jpeg); owner_dialog_id, std::move(size_ptr), PhotoFormat::Jpeg);
if (photo_size.get_offset() == 0) { if (photo_size.get_offset() == 0) {
PhotoSize &size = photo_size.get<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_) { for (auto &size_ptr : photo->video_sizes_) {
auto animation = 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)); photo->file_reference_.as_slice().str(), dc_id, owner_dialog_id, std::move(size_ptr));
if (animation.empty()) { if (animation.empty()) {
continue; 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); 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, Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFile> &&file,
tl_object_ptr<secret_api::decryptedMessageMediaPhoto> &&photo, DialogId owner_dialog_id); 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; 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()) { if (photo.is_empty()) {
LOG(ERROR) << "Receive a story with empty photo"; LOG(ERROR) << "Receive a story with empty photo";
break; 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()); 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, TRY_RESULT(file_id, td->file_manager_->get_input_file_id(FileType::Photo, input_story->photo_, owner_dialog_id,
false, false)); 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 = auto sticker_file_ids =
td->stickers_manager_->get_attached_sticker_file_ids(input_story->added_sticker_file_ids_); td->stickers_manager_->get_attached_sticker_file_ids(input_story->added_sticker_file_ids_);
TRY_RESULT(photo, TRY_RESULT(photo,

View File

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

View File

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

View File

@ -867,6 +867,7 @@ string FileManager::get_file_name(FileType file_type, Slice path) {
break; break;
case FileType::ProfilePhoto: case FileType::ProfilePhoto:
case FileType::Photo: case FileType::Photo:
case FileType::PhotoStory:
if (extension != "jpg" && extension != "jpeg" && extension != "gif" && extension != "png" && extension != "tif" && if (extension != "jpg" && extension != "jpeg" && extension != "gif" && extension != "png" && extension != "tif" &&
extension != "bmp") { extension != "bmp") {
return fix_file_extension(file_name, "photo", "jpg"); 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>(); return make_tl_object<td_api::fileTypeNotificationSound>();
case FileType::CallLog: case FileType::CallLog:
return make_tl_object<td_api::fileTypeDocument>(); return make_tl_object<td_api::fileTypeDocument>();
case FileType::PhotoStory:
return make_tl_object<td_api::fileTypePhoto>();
case FileType::None: case FileType::None:
return make_tl_object<td_api::fileTypeNone>(); return make_tl_object<td_api::fileTypeNone>();
default: default:
@ -111,6 +113,8 @@ FileType get_main_file_type(FileType file_type) {
return FileType::Document; return FileType::Document;
case FileType::CallLog: case FileType::CallLog:
return FileType::Document; return FileType::Document;
case FileType::PhotoStory:
return FileType::Photo;
default: default:
return file_type; return file_type;
} }
@ -150,6 +154,8 @@ CSlice get_file_type_name(FileType file_type) {
return CSlice("wallpapers"); return CSlice("wallpapers");
case FileType::Ringtone: case FileType::Ringtone:
return CSlice("notification_sounds"); return CSlice("notification_sounds");
case FileType::PhotoStory:
return CSlice("stories");
default: default:
UNREACHABLE(); UNREACHABLE();
return CSlice("none"); return CSlice("none");
@ -163,6 +169,7 @@ FileTypeClass get_file_type_class(FileType file_type) {
case FileType::Thumbnail: case FileType::Thumbnail:
case FileType::EncryptedThumbnail: case FileType::EncryptedThumbnail:
case FileType::Wallpaper: case FileType::Wallpaper:
case FileType::PhotoStory:
return FileTypeClass::Photo; return FileTypeClass::Photo;
case FileType::Video: case FileType::Video:
case FileType::VoiceNote: case FileType::VoiceNote:
@ -237,6 +244,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) {
return string_builder << "NotificationSound"; return string_builder << "NotificationSound";
case FileType::CallLog: case FileType::CallLog:
return string_builder << "CallLog"; return string_builder << "CallLog";
case FileType::PhotoStory:
return string_builder << "PhotoStory";
case FileType::Size: case FileType::Size:
case FileType::None: case FileType::None:
default: default:
@ -257,6 +266,7 @@ FileDirType get_file_dir_type(FileType file_type) {
case FileType::SecureDecrypted: case FileType::SecureDecrypted:
case FileType::Background: case FileType::Background:
case FileType::Ringtone: case FileType::Ringtone:
case FileType::PhotoStory:
return FileDirType::Secure; return FileDirType::Secure;
default: default:
return FileDirType::Common; return FileDirType::Common;
@ -286,6 +296,7 @@ bool can_reuse_remote_file(FileType file_type) {
case FileType::EncryptedThumbnail: case FileType::EncryptedThumbnail:
case FileType::Background: case FileType::Background:
case FileType::CallLog: case FileType::CallLog:
case FileType::PhotoStory:
return false; return false;
default: default:
return true; return true;

View File

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