Added support for animated thumbnails in inline animations.

GitOrigin-RevId: 5a8830d6e89256900335b8667405b2f81f22f5bd
This commit is contained in:
levlam 2020-05-15 19:48:21 +03:00
parent d647a2a2e8
commit ebf10667b7
3 changed files with 27 additions and 42 deletions

View File

@ -1857,17 +1857,14 @@ httpUrl url:string = HttpUrl;
//@class InputInlineQueryResult @description Represents a single result of an inline query; for bots only //@class InputInlineQueryResult @description Represents a single result of an inline query; for bots only
//@description Represents a link to an animated GIF @id Unique identifier of the query result @title Title of the query result @thumbnail_url URL of the static result thumbnail (JPEG or GIF), if it exists //@description Represents a link to an animated GIF or an animated (i.e. without sound) H.264/MPEG-4 AVC video
//@gif_url The URL of the GIF-file (file size must not exceed 1MB) @gif_duration Duration of the GIF, in seconds @gif_width Width of the GIF @gif_height Height of the GIF //@id Unique identifier of the query result @title Title of the query result
//@thumbnail_url URL of the result thumbnail (JPEG, GIF, or MPEG4), if it exists @thumbnail_mime_type MIME type of the video thumbnail. If non-empty, must be one of "image/jpeg", "image/gif" and "video/mp4"
//@video_url The URL of the video file (file size must not exceed 1MB) @video_mime_type MIME type of the video file. Must be one of "image/gif" and "video/mp4"
//@video_duration Duration of the video, in seconds @video_width Width of the video @video_height Height of the video
//@reply_markup The message reply markup. Must be of type replyMarkupInlineKeyboard or null //@reply_markup The message reply markup. Must be of type replyMarkupInlineKeyboard or null
//@input_message_content The content of the message to be sent. Must be one of the following types: InputMessageText, InputMessageAnimation, InputMessageLocation, InputMessageVenue or InputMessageContact //@input_message_content The content of the message to be sent. Must be one of the following types: InputMessageText, InputMessageAnimation, InputMessageLocation, InputMessageVenue or InputMessageContact
inputInlineQueryResultAnimatedGif id:string title:string thumbnail_url:string gif_url:string gif_duration:int32 gif_width:int32 gif_height:int32 reply_markup:ReplyMarkup input_message_content:InputMessageContent = InputInlineQueryResult; inputInlineQueryResultAnimation id:string title:string thumbnail_url:string thumbnail_mime_type:string video_url:string video_mime_type:string video_duration:int32 video_width:int32 video_height:int32 reply_markup:ReplyMarkup input_message_content:InputMessageContent = InputInlineQueryResult;
//@description Represents a link to an animated (i.e. without sound) H.264/MPEG-4 AVC video @id Unique identifier of the query result @title Title of the result @thumbnail_url URL of the static result thumbnail (JPEG or GIF), if it exists
//@mpeg4_url The URL of the MPEG4-file (file size must not exceed 1MB) @mpeg4_duration Duration of the video, in seconds @mpeg4_width Width of the video @mpeg4_height Height of the video
//@reply_markup The message reply markup. Must be of type replyMarkupInlineKeyboard or null
//@input_message_content The content of the message to be sent. Must be one of the following types: InputMessageText, InputMessageAnimation, InputMessageLocation, InputMessageVenue or InputMessageContact
inputInlineQueryResultAnimatedMpeg4 id:string title:string thumbnail_url:string mpeg4_url:string mpeg4_duration:int32 mpeg4_width:int32 mpeg4_height:int32 reply_markup:ReplyMarkup input_message_content:InputMessageContent = InputInlineQueryResult;
//@description Represents a link to an article or web page @id Unique identifier of the query result @url URL of the result, if it exists @hide_url True, if the URL must be not shown @title Title of the result //@description Represents a link to an article or web page @id Unique identifier of the query result @url URL of the result, if it exists @hide_url True, if the URL must be not shown @title Title of the result
//@param_description A short description of the result @thumbnail_url URL of the result thumbnail, if it exists @thumbnail_width Thumbnail width, if known @thumbnail_height Thumbnail height, if known //@param_description A short description of the result @thumbnail_url URL of the result thumbnail, if it exists @thumbnail_width Thumbnail width, if known @thumbnail_height Thumbnail height, if known

Binary file not shown.

View File

@ -350,6 +350,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
string title; string title;
string description; string description;
string thumbnail_url; string thumbnail_url;
string thumbnail_type = "image/jpeg";
string content_url; string content_url;
string content_type; string content_type;
int32 thumbnail_width = 0; int32 thumbnail_width = 0;
@ -361,42 +362,28 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
FileType file_type = FileType::Temp; FileType file_type = FileType::Temp;
Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> r_inline_message = Status::Error(500, "Uninited"); Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> r_inline_message = Status::Error(500, "Uninited");
switch (input_result->get_id()) { switch (input_result->get_id()) {
case td_api::inputInlineQueryResultAnimatedGif::ID: { case td_api::inputInlineQueryResultAnimation::ID: {
auto animated_gif = move_tl_object_as<td_api::inputInlineQueryResultAnimatedGif>(input_result); auto animation = move_tl_object_as<td_api::inputInlineQueryResultAnimation>(input_result);
type = "gif"; type = "gif";
id = std::move(animated_gif->id_); id = std::move(animation->id_);
title = std::move(animated_gif->title_); title = std::move(animation->title_);
thumbnail_url = std::move(animated_gif->thumbnail_url_); thumbnail_url = std::move(animation->thumbnail_url_);
content_url = std::move(animated_gif->gif_url_); if (!animation->thumbnail_mime_type_.empty()) {
content_type = "image/gif"; thumbnail_type = std::move(animation->thumbnail_mime_type_);
// duration = animated_gif->gif_duration_; }
width = animated_gif->gif_width_; content_url = std::move(animation->video_url_);
height = animated_gif->gif_height_; content_type = std::move(animation->video_mime_type_);
if (content_type != "image/gif" && content_type != "video/mp4") {
return promise.set_error(Status::Error(400, "Wrong animation MIME type specified"));
}
duration = animation->video_duration_;
width = animation->video_width_;
height = animation->video_height_;
is_gallery = true; is_gallery = true;
file_type = FileType::Animation; file_type = FileType::Animation;
r_inline_message = r_inline_message = get_inline_message(std::move(animation->input_message_content_),
get_inline_message(std::move(animated_gif->input_message_content_), std::move(animated_gif->reply_markup_), std::move(animation->reply_markup_), td_api::inputMessageAnimation::ID);
td_api::inputMessageAnimation::ID);
break;
}
case td_api::inputInlineQueryResultAnimatedMpeg4::ID: {
auto animated_mpeg4 = move_tl_object_as<td_api::inputInlineQueryResultAnimatedMpeg4>(input_result);
type = "gif";
id = std::move(animated_mpeg4->id_);
title = std::move(animated_mpeg4->title_);
thumbnail_url = std::move(animated_mpeg4->thumbnail_url_);
content_url = std::move(animated_mpeg4->mpeg4_url_);
content_type = "video/mp4";
duration = animated_mpeg4->mpeg4_duration_;
width = animated_mpeg4->mpeg4_width_;
height = animated_mpeg4->mpeg4_height_;
is_gallery = true;
file_type = FileType::Animation;
r_inline_message =
get_inline_message(std::move(animated_mpeg4->input_message_content_),
std::move(animated_mpeg4->reply_markup_), td_api::inputMessageAnimation::ID);
break; break;
} }
case td_api::inputInlineQueryResultArticle::ID: { case td_api::inputInlineQueryResultArticle::ID: {
@ -701,7 +688,8 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
attributes.push_back( attributes.push_back(
make_tl_object<telegram_api::documentAttributeImageSize>(thumbnail_width, thumbnail_height)); make_tl_object<telegram_api::documentAttributeImageSize>(thumbnail_width, thumbnail_height));
} }
thumbnail = make_tl_object<telegram_api::inputWebDocument>(thumbnail_url, 0, "image/jpeg", std::move(attributes)); thumbnail =
make_tl_object<telegram_api::inputWebDocument>(thumbnail_url, 0, thumbnail_type, std::move(attributes));
} }
tl_object_ptr<telegram_api::inputWebDocument> content; tl_object_ptr<telegram_api::inputWebDocument> content;
if (!content_url.empty() || !content_type.empty()) { if (!content_url.empty() || !content_type.empty()) {