Support stickers attached to animation.

GitOrigin-RevId: 3e2464146410fbc68b51721b10327f1ac92cbb66
This commit is contained in:
levlam 2020-05-29 11:51:51 +03:00
parent 3d8ff7f852
commit e8cb1dfeb5
11 changed files with 75 additions and 31 deletions

View File

@ -224,8 +224,9 @@ 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 @animation File containing the animation
animation duration:int32 width:int32 height:int32 file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:photoSize animation:file = Animation;
animation duration:int32 width:int32 height:int32 file_name:string mime_type:string has_stickers:Bool minithumbnail:minithumbnail thumbnail:photoSize 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
@ -235,7 +236,8 @@ audio duration:int32 title:string performer:string file_name:string mime_type:st
//@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;
//@description Describes a photo @has_stickers True, if stickers were added to the photo @minithumbnail Photo minithumbnail; may be null @sizes Available variants of the photo, in different sizes
//@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
@ -243,7 +245,8 @@ photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector<photoSize> = Ph
sticker set_id:int64 width:int32 height:int32 emoji:string is_animated:Bool is_mask:Bool mask_position:maskPosition thumbnail:photoSize 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
//@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 @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 video:file = Video;
@ -1562,8 +1565,9 @@ sendMessageOptions disable_notification:Bool from_background:Bool scheduling_sta
//@disable_web_page_preview True, if rich web page previews for URLs in the message text should be disabled @clear_draft True, if a chat message draft should be deleted
inputMessageText text:formattedText disable_web_page_preview:Bool clear_draft:Bool = InputMessageContent;
//@description An animation message (GIF-style). @animation Animation file to be sent @thumbnail Animation thumbnail, if available @duration Duration of the animation, in seconds @width Width of the animation; may be replaced by the server @height Height of the animation; may be replaced by the server @caption Animation caption; 0-GetOption("message_caption_length_max") characters
inputMessageAnimation animation:InputFile thumbnail:inputThumbnail duration:int32 width:int32 height:int32 caption:formattedText = InputMessageContent;
//@description An animation message (GIF-style). @animation Animation file to be sent @thumbnail Animation thumbnail, if available @added_sticker_file_ids File identifiers of the stickers added to the animation, if applicable
//@duration Duration of the animation, in seconds @width Width of the animation; may be replaced by the server @height Height of the animation; may be replaced by the server @caption Animation caption; 0-GetOption("message_caption_length_max") characters
inputMessageAnimation animation:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 caption:formattedText = InputMessageContent;
//@description An audio message @audio Audio file to be sent @album_cover_thumbnail Thumbnail of the cover for the album, if available @duration Duration of the audio, in seconds; may be replaced by the server @title Title of the audio; 0-64 characters; may be replaced by the server
//@performer Performer of the audio; 0-64 characters, may be replaced by the server @caption Audio caption; 0-GetOption("message_caption_length_max") characters

Binary file not shown.

View File

@ -161,7 +161,7 @@ tl_object_ptr<td_api::animation> AnimationsManager::get_animation_object(FileId
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,
get_minithumbnail_object(animation->minithumbnail),
animation->has_stickers, get_minithumbnail_object(animation->minithumbnail),
get_photo_size_object(td_->file_manager_.get(), &animation->thumbnail),
td_->file_manager_->get_file_object(file_id));
}
@ -210,6 +210,14 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
a->thumbnail = new_animation->thumbnail;
a->is_changed = true;
}
if (a->has_stickers != new_animation->has_stickers && new_animation->has_stickers) {
a->has_stickers = new_animation->has_stickers;
a->is_changed = true;
}
if (a->sticker_file_ids != new_animation->sticker_file_ids && !new_animation->sticker_file_ids.empty()) {
a->sticker_file_ids = std::move(new_animation->sticker_file_ids);
a->is_changed = true;
}
}
return file_id;
@ -288,8 +296,9 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_
return true;
}
void AnimationsManager::create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name,
string mime_type, int32 duration, Dimensions dimensions, bool replace) {
void AnimationsManager::create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, bool has_stickers,
vector<FileId> &&sticker_file_ids, string file_name, string mime_type,
int32 duration, Dimensions dimensions, bool replace) {
auto a = make_unique<Animation>();
a->file_id = file_id;
a->file_name = std::move(file_name);
@ -298,6 +307,8 @@ void AnimationsManager::create_animation(FileId file_id, string minithumbnail, P
a->dimensions = dimensions;
a->minithumbnail = std::move(minithumbnail);
a->thumbnail = std::move(thumbnail);
a->has_stickers = has_stickers;
a->sticker_file_ids = std::move(sticker_file_ids);
on_get_animation(std::move(a), replace);
}
@ -336,6 +347,11 @@ tl_object_ptr<telegram_api::InputMedia> AnimationsManager::get_input_media(
animation->dimensions.height));
}
int32 flags = 0;
vector<tl_object_ptr<telegram_api::InputDocument>> added_stickers;
if (animation->has_stickers) {
flags |= telegram_api::inputMediaUploadedDocument::STICKERS_MASK;
added_stickers = td_->file_manager_->get_input_documents(animation->sticker_file_ids);
}
if (input_thumbnail != nullptr) {
flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK;
}

View File

@ -35,8 +35,9 @@ class AnimationsManager : public Actor {
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id, const char *source);
void create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type,
int32 duration, Dimensions dimensions, bool replace);
void create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, bool has_stickers,
vector<FileId> &&sticker_file_ids, string file_name, string mime_type, int32 duration,
Dimensions dimensions, bool replace);
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file,
@ -98,6 +99,9 @@ class AnimationsManager : public Actor {
string minithumbnail;
PhotoSize thumbnail;
bool has_stickers = false;
vector<FileId> sticker_file_ids;
FileId file_id;
bool is_changed = true;

View File

@ -22,6 +22,9 @@ void AnimationsManager::store_animation(FileId file_id, StorerT &storer) const {
auto it = animations_.find(file_id);
CHECK(it != animations_.end());
const Animation *animation = it->second.get();
BEGIN_STORE_FLAGS();
STORE_FLAG(animation->has_stickers);
END_STORE_FLAGS();
store(animation->duration, storer);
store(animation->dimensions, storer);
store(animation->file_name, storer);
@ -29,11 +32,19 @@ void AnimationsManager::store_animation(FileId file_id, StorerT &storer) const {
store(animation->minithumbnail, storer);
store(animation->thumbnail, storer);
store(file_id, storer);
if (animation->has_stickers) {
store(animation->sticker_file_ids, storer);
}
}
template <class ParserT>
FileId AnimationsManager::parse_animation(ParserT &parser) {
auto animation = make_unique<Animation>();
if (parser.version() >= static_cast<int32>(Version::AddAnimationStickers)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(animation->has_stickers);
END_PARSE_FLAGS();
}
if (parser.version() >= static_cast<int32>(Version::AddDurationToAnimation)) {
parse(animation->duration, parser);
}
@ -45,6 +56,9 @@ FileId AnimationsManager::parse_animation(ParserT &parser) {
}
parse(animation->thumbnail, parser);
parse(animation->file_id, parser);
if (animation->has_stickers) {
parse(animation->sticker_file_ids, parser);
}
if (parser.get_error() != nullptr || !animation->file_id.is_valid()) {
return FileId();
}

View File

@ -388,10 +388,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
switch (document_type) {
case Document::Type::Animation:
// TODO use has_stickers
td_->animations_manager_->create_animation(file_id, std::move(minithumbnail), std::move(thumbnail),
std::move(file_name), std::move(mime_type), video_duration, dimensions,
!is_web);
td_->animations_manager_->create_animation(file_id, std::move(minithumbnail), std::move(thumbnail), has_stickers,
vector<FileId>(), std::move(file_name), std::move(mime_type),
video_duration, dimensions, !is_web);
break;
case Document::Type::Audio: {
int32 duration = 0;

View File

@ -894,7 +894,8 @@ tl_object_ptr<td_api::maskPosition> copy(const td_api::maskPosition &obj) {
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_,
copy(obj.minithumbnail_), copy(obj.thumbnail_), copy(obj.animation_));
obj.has_stickers_, copy(obj.minithumbnail_), copy(obj.thumbnail_),
copy(obj.animation_));
}
template <>

View File

@ -1473,9 +1473,11 @@ static Result<InputMessageContent> create_input_message_content(
case td_api::inputMessageAnimation::ID: {
auto input_animation = static_cast<td_api::inputMessageAnimation *>(input_message_content.get());
td->animations_manager_->create_animation(
file_id, string(), thumbnail, std::move(file_name), std::move(mime_type), input_animation->duration_,
get_dimensions(input_animation->width_, input_animation->height_), false);
bool has_stickers = !sticker_file_ids.empty();
td->animations_manager_->create_animation(file_id, string(), thumbnail, has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), input_animation->duration_,
get_dimensions(input_animation->width_, input_animation->height_),
false);
content = make_unique<MessageAnimation>(file_id, std::move(caption));
break;
@ -1840,6 +1842,9 @@ Result<InputMessageContent> get_input_message_content(
r_file_id = td->file_manager_->get_input_file_id(FileType::Animation, input_message->animation_, dialog_id, false,
is_secret, true);
input_thumbnail = std::move(input_message->thumbnail_);
if (!input_message->added_sticker_file_ids_.empty()) {
sticker_file_ids = td->stickers_manager_->get_attached_sticker_file_ids(input_message->added_sticker_file_ids_);
}
break;
}
case td_api::inputMessageAudio::ID: {

View File

@ -37,6 +37,7 @@ enum class Version : int32 {
AddFolders,
SupportPolls2_0,
AddDiceEmoji,
AddAnimationStickers,
Next
};

View File

@ -89,7 +89,7 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
v->is_changed = true;
}
if (v->sticker_file_ids != new_video->sticker_file_ids && !new_video->sticker_file_ids.empty()) {
v->sticker_file_ids = new_video->sticker_file_ids;
v->sticker_file_ids = std::move(new_video->sticker_file_ids);
v->is_changed = true;
}
}

View File

@ -2939,8 +2939,8 @@ class CliClient final : public Actor {
std::tie(message_id, animation) = split(args);
send_request(td_api::make_object<td_api::editMessageMedia>(
as_chat_id(chat_id), as_message_id(message_id), nullptr,
td_api::make_object<td_api::inputMessageAnimation>(as_input_file(animation), nullptr, 0, 0, 0,
as_caption("animation"))));
td_api::make_object<td_api::inputMessageAnimation>(as_input_file(animation), nullptr, vector<int32>(), 0, 0,
0, as_caption("animation"))));
} else if (op == "emc") {
string chat_id;
string message_id;
@ -3072,7 +3072,7 @@ class CliClient final : public Actor {
std::tie(height, caption) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_input_file(animation_path), nullptr, 60, to_integer<int32>(width),
as_input_file(animation_path), nullptr, vector<int32>(), 60, to_integer<int32>(width),
to_integer<int32>(height), as_caption(caption)));
} else if (op == "sang") {
string chat_id;
@ -3080,30 +3080,30 @@ class CliClient final : public Actor {
string animation_conversion;
std::tie(chat_id, args) = split(args);
std::tie(animation_path, animation_conversion) = split(args);
send_message(chat_id,
td_api::make_object<td_api::inputMessageAnimation>(
as_generated_file(animation_path, animation_conversion), nullptr, 60, 0, 0, as_caption("")));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_generated_file(animation_path, animation_conversion), nullptr, vector<int32>(), 60,
0, 0, as_caption("")));
} else if (op == "sanid") {
string chat_id;
string file_id;
std::tie(chat_id, file_id) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_input_file_id(file_id), nullptr, 0, 0,
0, as_caption("")));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_input_file_id(file_id), nullptr, vector<int32>(), 0, 0, 0, as_caption("")));
} else if (op == "sanurl") {
string chat_id;
string url;
std::tie(chat_id, url) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_generated_file(url, "#url#"), nullptr,
0, 0, 0, as_caption("")));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_generated_file(url, "#url#"), nullptr, vector<int32>(), 0, 0, 0, as_caption("")));
} else if (op == "sanurl2") {
string chat_id;
string url;
std::tie(chat_id, url) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_remote_file(url), nullptr, 0, 0, 0,
as_caption("")));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_remote_file(url), nullptr, vector<int32>(), 0, 0, 0, as_caption("")));
} else if (op == "sau") {
string chat_id;
string audio_path;