Add get_input_thumbnail_photo_size.

This commit is contained in:
levlam 2023-05-21 23:05:28 +03:00
parent c18818013a
commit c70ef59cde
3 changed files with 30 additions and 21 deletions

View File

@ -2365,33 +2365,16 @@ Result<InputMessageContent> get_input_message_content(
CHECK(file_id.is_valid());
}
PhotoSize thumbnail;
if (input_thumbnail != nullptr) {
auto r_thumbnail_file_id =
td->file_manager_->get_input_thumbnail_file_id(input_thumbnail->thumbnail_, dialog_id, is_secret);
if (r_thumbnail_file_id.is_error()) {
LOG(WARNING) << "Ignore thumbnail file: " << r_thumbnail_file_id.error().message();
} else {
thumbnail.type = 't';
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_, nullptr);
thumbnail.file_id = r_thumbnail_file_id.ok();
CHECK(thumbnail.file_id.is_valid());
FileView thumbnail_file_view = td->file_manager_->get_file_view(thumbnail.file_id);
if (thumbnail_file_view.has_remote_location()) {
// TODO td->file_manager_->delete_remote_location(thumbnail.file_id);
}
}
}
bool is_bot = td->auth_manager_->is_bot();
TRY_RESULT(caption, get_formatted_text(td, dialog_id, extract_input_caption(input_message_content), is_bot, true,
false, false));
if (is_bot && static_cast<int64>(utf8_length(caption.text)) > G()->get_option_integer("message_caption_length_max")) {
return Status::Error(400, "Message caption is too long");
}
return create_input_message_content(dialog_id, std::move(input_message_content), td, std::move(caption), file_id,
std::move(thumbnail), std::move(sticker_file_ids), is_premium);
return create_input_message_content(
dialog_id, std::move(input_message_content), td, std::move(caption), file_id,
get_input_thumbnail_photo_size(td->file_manager_.get(), input_thumbnail.get(), dialog_id, is_secret),
std::move(sticker_file_ids), is_premium);
}
bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server) {

View File

@ -444,6 +444,29 @@ Result<PhotoSize> get_input_photo_size(FileManager *file_manager, FileId file_id
return std::move(result);
}
PhotoSize get_input_thumbnail_photo_size(FileManager *file_manager, const td_api::inputThumbnail *input_thumbnail,
DialogId dialog_id, bool is_secret) {
PhotoSize thumbnail;
if (input_thumbnail != nullptr) {
auto r_thumbnail_file_id =
file_manager->get_input_thumbnail_file_id(input_thumbnail->thumbnail_, dialog_id, is_secret);
if (r_thumbnail_file_id.is_error()) {
LOG(WARNING) << "Ignore thumbnail file: " << r_thumbnail_file_id.error().message();
} else {
thumbnail.type = 't';
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_, nullptr);
thumbnail.file_id = r_thumbnail_file_id.ok();
CHECK(thumbnail.file_id.is_valid());
FileView thumbnail_file_view = file_manager->get_file_view(thumbnail.file_id);
if (thumbnail_file_view.has_remote_location()) {
// TODO file_manager->delete_remote_location(thumbnail.file_id);
}
}
}
return thumbnail;
}
td_api::object_ptr<td_api::thumbnail> get_thumbnail_object(FileManager *file_manager, const PhotoSize &photo_size,
PhotoFormat format) {
if (!photo_size.file_id.is_valid()) {

View File

@ -68,6 +68,9 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
Result<PhotoSize> get_input_photo_size(FileManager *file_manager, FileId file_id, int32 width, int32 height);
PhotoSize get_input_thumbnail_photo_size(FileManager *file_manager, const td_api::inputThumbnail *input_thumbnail,
DialogId dialog_id, bool is_secret);
td_api::object_ptr<td_api::thumbnail> get_thumbnail_object(FileManager *file_manager, const PhotoSize &photo_size,
PhotoFormat format);