From fc8265762640fd6fedb4f9e1c092bf1919ac6c86 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 22 May 2023 15:35:25 +0300 Subject: [PATCH] Add create_photo function. --- td/telegram/MessageContent.cpp | 29 ++++------------------------- td/telegram/Photo.cpp | 23 +++++++++++++++++++++++ td/telegram/Photo.h | 9 +++++++++ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 1c02eb3fd..e6bbd1bc3 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2076,32 +2076,11 @@ static Result create_input_message_content( ttl = input_photo->self_destruct_time_; - TRY_RESULT(input_photo_size, - get_input_photo_size(td->file_manager_.get(), file_id, input_photo->width_, input_photo->height_)); + TRY_RESULT(photo, create_photo(td->file_manager_.get(), file_id, std::move(thumbnail), input_photo->width_, + input_photo->height_, std::move(sticker_file_ids))); - auto message_photo = make_unique(); - - if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { - message_photo->photo.id = file_view.remote_location().get_id(); - } - if (message_photo->photo.is_empty()) { - message_photo->photo.id = 0; - } - message_photo->photo.date = G()->unix_time(); - - if (thumbnail.file_id.is_valid()) { - message_photo->photo.photos.push_back(std::move(thumbnail)); - } - - message_photo->photo.photos.push_back(std::move(input_photo_size)); - - message_photo->photo.has_stickers = !sticker_file_ids.empty(); - message_photo->photo.sticker_file_ids = std::move(sticker_file_ids); - - message_photo->caption = std::move(caption); - message_photo->has_spoiler = input_photo->has_spoiler_ && !is_secret; - - content = std::move(message_photo); + content = + make_unique(std::move(photo), std::move(caption), input_photo->has_spoiler_ && !is_secret); break; } case td_api::inputMessageSticker::ID: { diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 4e500a6af..ad5597530 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -11,6 +11,7 @@ #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/net/DcId.h" #include "td/telegram/PhotoFormat.h" #include "td/telegram/PhotoSizeSource.h" @@ -367,6 +368,28 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr create_photo(FileManager *file_manager, FileId file_id, PhotoSize &&thumbnail, int32 width, int32 height, + vector &&sticker_file_ids) { + TRY_RESULT(input_photo_size, get_input_photo_size(file_manager, file_id, width, height)); + + Photo photo; + auto file_view = file_manager->get_file_view(file_id); + if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { + photo.id = file_view.remote_location().get_id(); + } + if (photo.is_empty()) { + photo.id = 0; + } + photo.date = G()->unix_time(); + if (thumbnail.file_id.is_valid()) { + photo.photos.push_back(std::move(thumbnail)); + } + photo.photos.push_back(std::move(input_photo_size)); + photo.has_stickers = !sticker_file_ids.empty(); + photo.sticker_file_ids = std::move(sticker_file_ids); + return photo; +} + tl_object_ptr get_photo_object(FileManager *file_manager, const Photo &photo) { if (photo.is_empty()) { return nullptr; diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index ae80920c0..f3c2470bb 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -20,6 +20,7 @@ #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/MovableValue.h" +#include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/unique_value_ptr.h" @@ -104,12 +105,20 @@ 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); + Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr &&file, tl_object_ptr &&photo, DialogId owner_dialog_id); + Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr web_document, DialogId owner_dialog_id); + +Result create_photo(FileManager *file_manager, FileId file_id, PhotoSize &&thumbnail, int32 width, int32 height, + vector &&sticker_file_ids); + tl_object_ptr get_photo_object(FileManager *file_manager, const Photo &photo); + tl_object_ptr get_chat_photo_object(FileManager *file_manager, const Photo &photo); void merge_photos(Td *td, const Photo *old_photo, Photo *new_photo, DialogId dialog_id, bool need_merge_files,