Add td_api::thumbnail.

GitOrigin-RevId: b74fa62e415816ce63d3bd4415bd2bb8d6aa3f8b
This commit is contained in:
levlam 2020-05-31 22:22:15 +03:00
parent 2098d08244
commit 8d0fa5ce77
18 changed files with 167 additions and 93 deletions

View File

@ -181,13 +181,32 @@ inputFileGenerated original_path:string conversion:string expected_size:int32 =
//@description Photo description @type Thumbnail type (see https://core.telegram.org/constructor/photoSize) @photo Information about the photo file @width Photo width @height Photo height
photoSize type:string photo:file width:int32 height:int32 = PhotoSize;
//@description A short animated thumbnail of a file in the MPEG4 format @width Animation width @height Animation height @animation The thumbnail
animatedThumbnail width:int32 height:int32 animation:file = AnimatedThumbnail;
//@description Thumbnail image of a very poor quality and low resolution @width Thumbnail width, usually doesn't exceed 40 @height Thumbnail height, usually doesn't exceed 40 @data The thumbnail in JPEG format
minithumbnail width:int32 height:int32 data:bytes = Minithumbnail;
//@class ThumbnailFormat @description Describes format of the thumbnail
//@description The thumbnail is in JPEG format
thumbnailFormatJpeg = ThumbnailFormat;
//@description The thumbnail is in PNG format. It will be used only for background patterns
thumbnailFormatPng = ThumbnailFormat;
//@description The thumbnail is in WEBP format. It will be used only for some stickers
thumbnailFormatWebp = ThumbnailFormat;
//@description The thumbnail is in TGS format. It will be used only for animated sticker sets
thumbnailFormatTgs = ThumbnailFormat;
//@description The thumbnail is in MPEG4 format. It will be used only for some animations and videos
thumbnailFormatMpeg4 = ThumbnailFormat;
//@description Represents a thumbnail @format Thumbnail format @width Thumbnail width @height Thumbnail height @thumbnail The thumbnail
thumbnail format:ThumbnailFormat width:int32 height:int32 thumbnail:file = Thumbnail;
//@class MaskPoint @description Part of the face, relative to which a mask should be placed
//@description A mask should be placed relatively to the forehead
@ -228,35 +247,38 @@ pollTypeQuiz correct_option_id:int32 explanation:formattedText = PollType;
//@description Describes an animation file. The animation must be encoded in GIF or MPEG4 format @duration Duration of the animation, in seconds; as defined by the sender @width Width of the animation @height Height of the animation
//@file_name Original name of the file; as defined by the sender @mime_type MIME type of the file, usually "image/gif" or "video/mp4"
//@has_stickers True, if stickers were added to the animation. The list of corresponding sticker set can be received using getAttachedStickerSets
//@minithumbnail Animation minithumbnail; may be null @thumbnail Animation thumbnail; may be null
//@animated_thumbnail A short animated thumbnail of the animation in the MPEG4 format; may be null @animation File containing the animation
animation duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool minithumbnail:minithumbnail thumbnail:photoSize animated_thumbnail:animatedThumbnail animation:file = Animation;
//@minithumbnail Animation minithumbnail; may be null @thumbnail Animation thumbnail in JPEG or MPEG4 format; may be null @animation File containing the animation
animation duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool minithumbnail:minithumbnail thumbnail:thumbnail animation:file = Animation;
//@description Describes an audio file. Audio is usually in MP3 or M4A format @duration Duration of the audio, in seconds; as defined by the sender @title Title of the audio; as defined by the sender @performer Performer of the audio; as defined by the sender
//@file_name Original name of the file; as defined by the sender @mime_type The MIME type of the file; as defined by the sender @album_cover_minithumbnail The minithumbnail of the album cover; may be null @album_cover_thumbnail The thumbnail of the album cover; as defined by the sender. The full size thumbnail should be extracted from the downloaded file; may be null @audio File containing the audio
audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:photoSize audio:file = Audio;
//@file_name Original name of the file; as defined by the sender @mime_type The MIME type of the file; as defined by the sender @album_cover_minithumbnail The minithumbnail of the album cover; may be null
//@album_cover_thumbnail The thumbnail of the album cover in JPEG format; as defined by the sender. The full size thumbnail should be extracted from the downloaded file; may be null @audio File containing the audio
audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:thumbnail audio:file = Audio;
//@description Describes a document of any type @file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender
//@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail in JPEG or PNG format (PNG will be used only for background patterns); as defined by the sender; may be null @document File containing the document
document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:photoSize document:file = Document;
document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:thumbnail document:file = Document;
//@description Describes a photo @has_stickers True, if stickers were added to the photo. The list of corresponding sticker sets can be received using getAttachedStickerSets
//@minithumbnail Photo minithumbnail; may be null @sizes Available variants of the photo, in different sizes
photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector<photoSize> = Photo;
//@description Describes a sticker @set_id The identifier of the sticker set to which the sticker belongs; 0 if none @width Sticker width; as defined by the sender @height Sticker height; as defined by the sender
//@emoji Emoji corresponding to the sticker @is_animated True, if the sticker is an animated sticker in TGS format @is_mask True, if the sticker is a mask @mask_position Position where the mask should be placed; may be null @thumbnail Sticker thumbnail in WEBP or JPEG format; may be null @sticker File containing the sticker
sticker set_id:int64 width:int32 height:int32 emoji:string is_animated:Bool is_mask:Bool mask_position:maskPosition thumbnail:photoSize sticker:file = Sticker;
//@emoji Emoji corresponding to the sticker @is_animated True, if the sticker is an animated sticker in TGS format @is_mask True, if the sticker is a mask @mask_position Position where the mask should be placed; may be null
//@thumbnail Sticker thumbnail in WEBP or JPEG format; may be null @sticker File containing the sticker
sticker set_id:int64 width:int32 height:int32 emoji:string is_animated:Bool is_mask:Bool mask_position:maskPosition thumbnail:thumbnail sticker:file = Sticker;
//@description Describes a video file @duration Duration of the video, in seconds; as defined by the sender @width Video width; as defined by the sender @height Video height; as defined by the sender
//@file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender
//@has_stickers True, if stickers were added to the video. The list of corresponding sticker sets can be received using getAttachedStickerSets
//@supports_streaming True, if the video should be tried to be streamed @minithumbnail Video minithumbnail; may be null @thumbnail Video thumbnail; as defined by the sender; may be null
//@animated_thumbnail A short animated thumbnail of the video in the MPEG4 format; may be null @video File containing the video
video duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool supports_streaming:Bool minithumbnail:minithumbnail thumbnail:photoSize animated_thumbnail:animatedThumbnail video:file = Video;
//@supports_streaming True, if the video should be tried to be streamed @minithumbnail Video minithumbnail; may be null
//@thumbnail Video thumbnail in JPEG or MPEG4 format; as defined by the sender; may be null @video File containing the video
video duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool supports_streaming:Bool minithumbnail:minithumbnail thumbnail:thumbnail video:file = Video;
//@description Describes a video note. The video must be equal in width and height, cropped to a circle, and stored in MPEG4 format @duration Duration of the video, in seconds; as defined by the sender @length Video width and height; as defined by the sender @minithumbnail Video minithumbnail; may be null @thumbnail Video thumbnail; as defined by the sender; may be null @video File containing the video
videoNote duration:int32 length:int32 minithumbnail:minithumbnail thumbnail:photoSize video:file = VideoNote;
//@description Describes a video note. The video must be equal in width and height, cropped to a circle, and stored in MPEG4 format @duration Duration of the video, in seconds; as defined by the sender
//@length Video width and height; as defined by the sender @minithumbnail Video minithumbnail; may be null
//@thumbnail Video thumbnail in JPEG format; as defined by the sender; may be null @video File containing the video
videoNote duration:int32 length:int32 minithumbnail:minithumbnail thumbnail:thumbnail video:file = VideoNote;
//@description Describes a voice note. The voice note must be encoded with the Opus codec, and stored inside an OGG container. Voice notes can have only a single audio channel @duration Duration of the voice note, in seconds; as defined by the sender
//@waveform A waveform representation of the voice note in 5-bit format @mime_type MIME type of the file; as defined by the sender @voice File containing the voice note
@ -1784,18 +1806,18 @@ stickers stickers:vector<sticker> = Stickers;
emojis emojis:vector<string> = Emojis;
//@description Represents a sticker set
//@id Identifier of the sticker set @title Title of the sticker set @name Name of the sticker set @thumbnail Sticker set thumbnail in WEBP format with width and height 100; may be null. The file can be downloaded only before the thumbnail is changed
//@id Identifier of the sticker set @title Title of the sticker set @name Name of the sticker set @thumbnail Sticker set thumbnail in WEBP or TGS format with width and height 100; may be null. The file can be downloaded only before the thumbnail is changed
//@is_installed True, if the sticker set has been installed by the current user @is_archived True, if the sticker set has been archived. A sticker set can't be installed and archived simultaneously
//@is_official True, if the sticker set is official @is_animated True, is the stickers in the set are animated @is_masks True, if the stickers in the set are masks @is_viewed True for already viewed trending sticker sets
//@stickers List of stickers in this set @emojis A list of emoji corresponding to the stickers in the same order. The list is only for informational purposes, because a sticker is always sent with a fixed emoji from the corresponding Sticker object
stickerSet id:int64 title:string name:string thumbnail:photoSize is_installed:Bool is_archived:Bool is_official:Bool is_animated:Bool is_masks:Bool is_viewed:Bool stickers:vector<sticker> emojis:vector<emojis> = StickerSet;
stickerSet id:int64 title:string name:string thumbnail:thumbnail is_installed:Bool is_archived:Bool is_official:Bool is_animated:Bool is_masks:Bool is_viewed:Bool stickers:vector<sticker> emojis:vector<emojis> = StickerSet;
//@description Represents short information about a sticker set
//@id Identifier of the sticker set @title Title of the sticker set @name Name of the sticker set @thumbnail Sticker set thumbnail in WEBP format with width and height 100; may be null
//@id Identifier of the sticker set @title Title of the sticker set @name Name of the sticker set @thumbnail Sticker set thumbnail in WEBP or TGS format with width and height 100; may be null
//@is_installed True, if the sticker set has been installed by current user @is_archived True, if the sticker set has been archived. A sticker set can't be installed and archived simultaneously
//@is_official True, if the sticker set is official @is_animated True, is the stickers in the set are animated @is_masks True, if the stickers in the set are masks @is_viewed True for already viewed trending sticker sets
//@size Total number of stickers in the set @covers Contains up to the first 5 stickers from the set, depending on the context. If the client needs more stickers the full set should be requested
stickerSetInfo id:int64 title:string name:string thumbnail:photoSize is_installed:Bool is_archived:Bool is_official:Bool is_animated:Bool is_masks:Bool is_viewed:Bool size:int32 covers:vector<sticker> = StickerSetInfo;
stickerSetInfo id:int64 title:string name:string thumbnail:thumbnail is_installed:Bool is_archived:Bool is_official:Bool is_animated:Bool is_masks:Bool is_viewed:Bool size:int32 covers:vector<sticker> = StickerSetInfo;
//@description Represents a list of sticker sets @total_count Approximate total number of sticker sets found @sets List of sticker sets
stickerSets total_count:int32 sets:vector<stickerSetInfo> = StickerSets;
@ -1980,17 +2002,17 @@ inputInlineQueryResultVoiceNote id:string title:string voice_note_url:string voi
//@class InlineQueryResult @description Represents a single result of an inline query
//@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 Result thumbnail; may be null
inlineQueryResultArticle id:string url:string hide_url:Bool title:string description:string thumbnail:photoSize = InlineQueryResult;
//@param_description A short description of the result @thumbnail Result thumbnail in JPEG format; may be null
inlineQueryResultArticle id:string url:string hide_url:Bool title:string description:string thumbnail:thumbnail = InlineQueryResult;
//@description Represents a user contact @id Unique identifier of the query result @contact A user contact @thumbnail Result thumbnail; may be null
inlineQueryResultContact id:string contact:contact thumbnail:photoSize = InlineQueryResult;
//@description Represents a user contact @id Unique identifier of the query result @contact A user contact @thumbnail Result thumbnail in JPEG format; may be null
inlineQueryResultContact id:string contact:contact thumbnail:thumbnail = InlineQueryResult;
//@description Represents a point on the map @id Unique identifier of the query result @location Location result @title Title of the result @thumbnail Result thumbnail; may be null
inlineQueryResultLocation id:string location:location title:string thumbnail:photoSize = InlineQueryResult;
//@description Represents a point on the map @id Unique identifier of the query result @location Location result @title Title of the result @thumbnail Result thumbnail in JPEG format; may be null
inlineQueryResultLocation id:string location:location title:string thumbnail:thumbnail = InlineQueryResult;
//@description Represents information about a venue @id Unique identifier of the query result @venue Venue result @thumbnail Result thumbnail; may be null
inlineQueryResultVenue id:string venue:venue thumbnail:photoSize = InlineQueryResult;
//@description Represents information about a venue @id Unique identifier of the query result @venue Venue result @thumbnail Result thumbnail in JPEG format; may be null
inlineQueryResultVenue id:string venue:venue thumbnail:thumbnail = InlineQueryResult;
//@description Represents information about a game @id Unique identifier of the query result @game Game result
inlineQueryResultGame id:string game:game = InlineQueryResult;

Binary file not shown.

View File

@ -160,12 +160,14 @@ tl_object_ptr<td_api::animation> AnimationsManager::get_animation_object(FileId
<< static_cast<int32>(td_->file_manager_->get_file_view(file_id).get_type());
// TODO can we make that function const?
animation->is_changed = false;
return make_tl_object<td_api::animation>(
animation->duration, animation->dimensions.width, animation->dimensions.height, animation->file_name,
animation->mime_type, animation->has_stickers, get_minithumbnail_object(animation->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &animation->thumbnail),
get_animated_thumbnail_object(td_->file_manager_.get(), &animation->animated_thumbnail),
td_->file_manager_->get_file_object(file_id));
auto thumbnail =
animation->animated_thumbnail.file_id.is_valid()
? get_thumbnail_object(td_->file_manager_.get(), animation->animated_thumbnail, PhotoFormat::Mpeg4)
: get_thumbnail_object(td_->file_manager_.get(), animation->thumbnail, PhotoFormat::Jpeg);
return make_tl_object<td_api::animation>(animation->duration, animation->dimensions.width,
animation->dimensions.height, animation->file_name, animation->mime_type,
animation->has_stickers, get_minithumbnail_object(animation->minithumbnail),
std::move(thumbnail), td_->file_manager_->get_file_object(file_id));
}
FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation, bool replace) {

View File

@ -36,10 +36,11 @@ tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) {
auto &audio = audios_[file_id];
CHECK(audio != nullptr);
audio->is_changed = false;
return make_tl_object<td_api::audio>(audio->duration, audio->title, audio->performer, audio->file_name,
audio->mime_type, get_minithumbnail_object(audio->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &audio->thumbnail),
td_->file_manager_->get_file_object(file_id));
return make_tl_object<td_api::audio>(
audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type,
get_minithumbnail_object(audio->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), audio->thumbnail, PhotoFormat::Jpeg),
td_->file_manager_->get_file_object(file_id));
}
FileId AudiosManager::on_get_audio(unique_ptr<Audio> new_audio, bool replace) {

View File

@ -1054,7 +1054,8 @@ td_api::object_ptr<td_api::background> BackgroundManager::get_background_object(
}
return td_api::make_object<td_api::background>(
background->id.get(), background->is_default, background->is_dark, background->name,
td_->documents_manager_->get_document_object(background->file_id), get_background_type_object(*type));
td_->documents_manager_->get_document_object(background->file_id, PhotoFormat::Png),
get_background_type_object(*type));
}
td_api::object_ptr<td_api::backgrounds> BackgroundManager::get_backgrounds_object(bool for_dark_theme) const {

View File

@ -48,7 +48,7 @@ namespace td {
DocumentsManager::DocumentsManager(Td *td) : td_(td) {
}
tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId file_id) {
tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId file_id, PhotoFormat thumbnail_format) {
if (!file_id.is_valid()) {
return nullptr;
}
@ -57,10 +57,10 @@ tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId fil
auto &document = documents_[file_id];
LOG_CHECK(document != nullptr) << tag("file_id", file_id);
document->is_changed = false;
return make_tl_object<td_api::document>(document->file_name, document->mime_type,
get_minithumbnail_object(document->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &document->thumbnail),
td_->file_manager_->get_file_object(file_id));
return make_tl_object<td_api::document>(
document->file_name, document->mime_type, get_minithumbnail_object(document->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), document->thumbnail, thumbnail_format),
td_->file_manager_->get_file_object(file_id));
}
Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
@ -234,6 +234,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
default_extension = Slice("tgs");
owner_dialog_id = DialogId();
file_name.clear();
thumbnail_format = PhotoFormat::Webp;
}
};

View File

@ -74,7 +74,7 @@ class DocumentsManager {
}
};
tl_object_ptr<td_api::document> get_document_object(FileId file_id);
tl_object_ptr<td_api::document> get_document_object(FileId file_id, PhotoFormat thumbnail_format);
Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
MultiPromiseActor *load_data_multipromise_ptr = nullptr,

View File

@ -866,8 +866,26 @@ tl_object_ptr<td_api::photoSize> copy(const td_api::photoSize &obj) {
}
template <>
tl_object_ptr<td_api::animatedThumbnail> copy(const td_api::animatedThumbnail &obj) {
return make_tl_object<td_api::animatedThumbnail>(obj.width_, obj.height_, copy(obj.animation_));
tl_object_ptr<td_api::thumbnail> copy(const td_api::thumbnail &obj) {
auto format = [&]() -> td_api::object_ptr<td_api::ThumbnailFormat> {
switch (obj.format_->get_id()) {
case td_api::thumbnailFormatJpeg::ID:
return td_api::make_object<td_api::thumbnailFormatJpeg>();
case td_api::thumbnailFormatPng::ID:
return td_api::make_object<td_api::thumbnailFormatPng>();
case td_api::thumbnailFormatWebp::ID:
return td_api::make_object<td_api::thumbnailFormatWebp>();
case td_api::thumbnailFormatTgs::ID:
return td_api::make_object<td_api::thumbnailFormatTgs>();
case td_api::thumbnailFormatMpeg4::ID:
return td_api::make_object<td_api::thumbnailFormatMpeg4>();
default:
UNREACHABLE();
return nullptr;
}
}();
return make_tl_object<td_api::thumbnail>(std::move(format), obj.width_, obj.height_, copy(obj.thumbnail_));
}
static tl_object_ptr<td_api::photoSize> copy_photo_size(const tl_object_ptr<td_api::photoSize> &obj) {
@ -900,7 +918,7 @@ template <>
tl_object_ptr<td_api::animation> copy(const td_api::animation &obj) {
return make_tl_object<td_api::animation>(obj.duration_, obj.width_, obj.height_, obj.file_name_, obj.mime_type_,
obj.has_stickers_, copy(obj.minithumbnail_), copy(obj.thumbnail_),
copy(obj.animated_thumbnail_), copy(obj.animation_));
copy(obj.animation_));
}
template <>
@ -933,7 +951,7 @@ template <>
tl_object_ptr<td_api::video> copy(const td_api::video &obj) {
return make_tl_object<td_api::video>(obj.duration_, obj.width_, obj.height_, obj.file_name_, obj.mime_type_,
obj.has_stickers_, obj.supports_streaming_, copy(obj.minithumbnail_),
copy(obj.thumbnail_), copy(obj.animated_thumbnail_), copy(obj.video_));
copy(obj.thumbnail_), copy(obj.video_));
}
template <>
@ -1066,7 +1084,7 @@ tl_object_ptr<td_api::inlineQueryResults> InlineQueriesManager::decrease_pending
return copy(it->second.results);
}
tl_object_ptr<td_api::photoSize> InlineQueriesManager::register_thumbnail(
tl_object_ptr<td_api::thumbnail> InlineQueriesManager::register_thumbnail(
tl_object_ptr<telegram_api::WebDocument> &&web_document_ptr) const {
PhotoSize thumbnail = get_web_document_photo_size(td_->file_manager_.get(), FileType::Thumbnail, DialogId(),
std::move(web_document_ptr));
@ -1074,7 +1092,7 @@ tl_object_ptr<td_api::photoSize> InlineQueriesManager::register_thumbnail(
return nullptr;
}
return get_photo_size_object(td_->file_manager_.get(), &thumbnail);
return get_thumbnail_object(td_->file_manager_.get(), thumbnail, PhotoFormat::Jpeg);
}
string InlineQueriesManager::get_web_document_url(const tl_object_ptr<telegram_api::WebDocument> &web_document_ptr) {
@ -1207,7 +1225,8 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
document->id_ = std::move(result->id_);
document->document_ = td_->documents_manager_->get_document_object(parsed_document.file_id);
document->document_ =
td_->documents_manager_->get_document_object(parsed_document.file_id, PhotoFormat::Jpeg);
document->title_ = std::move(result->title_);
document->description_ = std::move(result->description_);
@ -1473,7 +1492,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
} else if (result->type_ == "file" && parsed_document.type == Document::Type::General) {
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
document->id_ = std::move(result->id_);
document->document_ = td_->documents_manager_->get_document_object(file_id);
document->document_ = td_->documents_manager_->get_document_object(file_id, PhotoFormat::Jpeg);
document->title_ = std::move(result->title_);
document->description_ = std::move(result->description_);
if (!register_inline_message_content(results->query_id_, document->id_, file_id,

View File

@ -92,7 +92,7 @@ class InlineQueriesManager : public Actor {
tl_object_ptr<telegram_api::BotInlineMessage> &&inline_message,
int32 allowed_media_content_id, Photo *photo = nullptr, Game *game = nullptr);
tl_object_ptr<td_api::photoSize> register_thumbnail(
tl_object_ptr<td_api::thumbnail> register_thumbnail(
tl_object_ptr<telegram_api::WebDocument> &&web_document_ptr) const;
static string get_web_document_url(const tl_object_ptr<telegram_api::WebDocument> &web_document_ptr);

View File

@ -4366,8 +4366,9 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Document: {
const MessageDocument *m = static_cast<const MessageDocument *>(content);
return make_tl_object<td_api::messageDocument>(td->documents_manager_->get_document_object(m->file_id),
get_formatted_text_object(m->caption));
return make_tl_object<td_api::messageDocument>(
td->documents_manager_->get_document_object(m->file_id, PhotoFormat::Jpeg),
get_formatted_text_object(m->caption));
}
case MessageContentType::Game: {
const MessageGame *m = static_cast<const MessageGame *>(content);

View File

@ -216,7 +216,7 @@ class NotificationTypePushMessage : public NotificationType {
if (key == "MESSAGE_DOCUMENT") {
auto documents_manager = G()->td().get_actor_unsafe()->documents_manager_.get();
return td_api::make_object<td_api::pushMessageContentDocument>(
documents_manager->get_document_object(document.file_id), is_pinned);
documents_manager->get_document_object(document.file_id, PhotoFormat::Jpeg), is_pinned);
}
break;
case 'F':

View File

@ -95,6 +95,24 @@ td_api::object_ptr<td_api::minithumbnail> get_minithumbnail_object(const string
return nullptr;
}
static td_api::object_ptr<td_api::ThumbnailFormat> get_thumbnail_format_object(PhotoFormat format) {
switch (format) {
case PhotoFormat::Jpeg:
return td_api::make_object<td_api::thumbnailFormatJpeg>();
case PhotoFormat::Png:
return td_api::make_object<td_api::thumbnailFormatPng>();
case PhotoFormat::Webp:
return td_api::make_object<td_api::thumbnailFormatWebp>();
case PhotoFormat::Tgs:
return td_api::make_object<td_api::thumbnailFormatTgs>();
case PhotoFormat::Mpeg4:
return td_api::make_object<td_api::thumbnailFormatMpeg4>();
default:
UNREACHABLE();
return nullptr;
}
}
static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat format) {
switch (format) {
case PhotoFormat::Jpeg:
@ -468,7 +486,18 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
return s;
}
tl_object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size) {
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()) {
return nullptr;
}
return td_api::make_object<td_api::thumbnail>(get_thumbnail_format_object(format), photo_size.dimensions.width,
photo_size.dimensions.height,
file_manager->get_file_object(photo_size.file_id));
}
static tl_object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size) {
if (photo_size == nullptr || !photo_size->file_id.is_valid()) {
return nullptr;
}
@ -479,18 +508,8 @@ tl_object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager
file_manager->get_file_object(photo_size->file_id), photo_size->dimensions.width, photo_size->dimensions.height);
}
td_api::object_ptr<td_api::animatedThumbnail> get_animated_thumbnail_object(FileManager *file_manager,
const PhotoSize *photo_size) {
if (photo_size == nullptr || !photo_size->file_id.is_valid()) {
return nullptr;
}
return td_api::make_object<td_api::animatedThumbnail>(photo_size->dimensions.width, photo_size->dimensions.height,
file_manager->get_file_object(photo_size->file_id));
}
vector<td_api::object_ptr<td_api::photoSize>> get_photo_sizes_object(FileManager *file_manager,
const vector<PhotoSize> &photo_sizes) {
static vector<td_api::object_ptr<td_api::photoSize>> get_photo_sizes_object(FileManager *file_manager,
const vector<PhotoSize> &photo_sizes) {
auto sizes = transform(photo_sizes, [file_manager](const PhotoSize &photo_size) {
return get_photo_size_object(file_manager, &photo_size);
});

View File

@ -103,11 +103,8 @@ PhotoSize get_video_photo_size(FileManager *file_manager, PhotoSizeSource source
tl_object_ptr<telegram_api::videoSize> &&size);
PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id,
tl_object_ptr<telegram_api::WebDocument> web_document_ptr);
td_api::object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size);
vector<td_api::object_ptr<td_api::photoSize>> get_photo_sizes_object(FileManager *file_manager,
const vector<PhotoSize> &photo_sizes);
td_api::object_ptr<td_api::animatedThumbnail> get_animated_thumbnail_object(FileManager *file_manager,
const PhotoSize *photo_size);
td_api::object_ptr<td_api::thumbnail> get_thumbnail_object(FileManager *file_manager, const PhotoSize &photo_size,
PhotoFormat format);
bool operator==(const PhotoSize &lhs, const PhotoSize &rhs);
bool operator!=(const PhotoSize &lhs, const PhotoSize &rhs);

View File

@ -1341,10 +1341,18 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
: nullptr;
const PhotoSize &thumbnail = sticker->m_thumbnail.file_id.is_valid() ? sticker->m_thumbnail : sticker->s_thumbnail;
auto thumbnail_format = PhotoFormat::Webp;
if (!sticker->set_id.is_valid()) {
auto file_view = td_->file_manager_->get_file_view(sticker->file_id);
if (file_view.is_encrypted()) {
// uploaded to secret chats stickers have JPEG thumbnail instead of server-generated WEBP
thumbnail_format = PhotoFormat::Jpeg;
}
}
auto thumbnail_object = get_thumbnail_object(td_->file_manager_.get(), thumbnail, thumbnail_format);
return make_tl_object<td_api::sticker>(sticker->set_id.get(), sticker->dimensions.width, sticker->dimensions.height,
sticker->alt, sticker->is_animated, sticker->is_mask, std::move(mask_position),
get_photo_size_object(td_->file_manager_.get(), &thumbnail),
td_->file_manager_->get_file_object(file_id));
std::move(thumbnail_object), td_->file_manager_->get_file_object(file_id));
}
tl_object_ptr<td_api::stickers> StickersManager::get_stickers_object(const vector<FileId> &sticker_ids) const {
@ -1414,9 +1422,10 @@ tl_object_ptr<td_api::stickerSet> StickersManager::get_sticker_set_object(Sticke
emojis.push_back(make_tl_object<td_api::emojis>(vector<string>(it->second)));
}
}
auto thumbnail = get_thumbnail_object(td_->file_manager_.get(), sticker_set->thumbnail,
sticker_set->is_animated ? PhotoFormat::Tgs : PhotoFormat::Webp);
return make_tl_object<td_api::stickerSet>(
sticker_set->id.get(), sticker_set->title, sticker_set->short_name,
get_photo_size_object(td_->file_manager_.get(), &sticker_set->thumbnail),
sticker_set->id.get(), sticker_set->title, sticker_set->short_name, std::move(thumbnail),
sticker_set->is_installed && !sticker_set->is_archived, sticker_set->is_archived, sticker_set->is_official,
sticker_set->is_animated, sticker_set->is_masks, sticker_set->is_viewed, std::move(stickers), std::move(emojis));
}
@ -1458,9 +1467,10 @@ tl_object_ptr<td_api::stickerSetInfo> StickersManager::get_sticker_set_info_obje
}
}
auto thumbnail = get_thumbnail_object(td_->file_manager_.get(), sticker_set->thumbnail,
sticker_set->is_animated ? PhotoFormat::Tgs : PhotoFormat::Webp);
return make_tl_object<td_api::stickerSetInfo>(
sticker_set->id.get(), sticker_set->title, sticker_set->short_name,
get_photo_size_object(td_->file_manager_.get(), &sticker_set->thumbnail),
sticker_set->id.get(), sticker_set->title, sticker_set->short_name, std::move(thumbnail),
sticker_set->is_installed && !sticker_set->is_archived, sticker_set->is_archived, sticker_set->is_official,
sticker_set->is_animated, sticker_set->is_masks, sticker_set->is_viewed,
sticker_set->was_loaded ? narrow_cast<int32>(sticker_set->sticker_ids.size()) : sticker_set->sticker_count,

View File

@ -38,10 +38,10 @@ tl_object_ptr<td_api::videoNote> VideoNotesManager::get_video_note_object(FileId
CHECK(video_note != nullptr);
video_note->is_changed = false;
return make_tl_object<td_api::videoNote>(video_note->duration, video_note->dimensions.width,
get_minithumbnail_object(video_note->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &video_note->thumbnail),
td_->file_manager_->get_file_object(file_id));
return make_tl_object<td_api::videoNote>(
video_note->duration, video_note->dimensions.width, get_minithumbnail_object(video_note->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), video_note->thumbnail, PhotoFormat::Jpeg),
td_->file_manager_->get_file_object(file_id));
}
FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note, bool replace) {

View File

@ -37,12 +37,13 @@ tl_object_ptr<td_api::video> VideosManager::get_video_object(FileId file_id) {
CHECK(video != nullptr);
video->is_changed = false;
return make_tl_object<td_api::video>(
video->duration, video->dimensions.width, video->dimensions.height, video->file_name, video->mime_type,
video->has_stickers, video->supports_streaming, get_minithumbnail_object(video->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &video->thumbnail),
get_animated_thumbnail_object(td_->file_manager_.get(), &video->animated_thumbnail),
td_->file_manager_->get_file_object(file_id));
auto thumbnail = video->animated_thumbnail.file_id.is_valid()
? get_thumbnail_object(td_->file_manager_.get(), video->animated_thumbnail, PhotoFormat::Mpeg4)
: get_thumbnail_object(td_->file_manager_.get(), video->thumbnail, PhotoFormat::Jpeg);
return make_tl_object<td_api::video>(video->duration, video->dimensions.width, video->dimensions.height,
video->file_name, video->mime_type, video->has_stickers,
video->supports_streaming, get_minithumbnail_object(video->minithumbnail),
std::move(thumbnail), td_->file_manager_->get_file_object(file_id));
}
FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {

View File

@ -156,7 +156,7 @@ class RichText {
auto width = static_cast<int32>(dimensions / 65536);
auto height = static_cast<int32>(dimensions % 65536);
return make_tl_object<td_api::richTextIcon>(
context->td_->documents_manager_->get_document_object(document_file_id), width, height);
context->td_->documents_manager_->get_document_object(document_file_id, PhotoFormat::Jpeg), width, height);
}
case RichText::Type::Anchor: {
if (context->is_first_pass_) {

View File

@ -1264,7 +1264,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
? td_->audios_manager_->get_audio_object(web_page->document.file_id)
: nullptr,
web_page->document.type == Document::Type::General
? td_->documents_manager_->get_document_object(web_page->document.file_id)
? td_->documents_manager_->get_document_object(web_page->document.file_id, PhotoFormat::Jpeg)
: nullptr,
web_page->document.type == Document::Type::Sticker
? td_->stickers_manager_->get_sticker_object(web_page->document.file_id)