Support premium stickers.
This commit is contained in:
parent
f8077965ad
commit
447cfbfb1d
@ -296,8 +296,8 @@ photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector<photoSize> = Ph
|
||||
|
||||
//@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 @type Sticker type @outline Sticker's outline represented as a list of closed vector paths; may be empty. The coordinate system origin is in the upper-left corner
|
||||
//@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 type:StickerType outline:vector<closedVectorPath> thumbnail:thumbnail sticker:file = Sticker;
|
||||
//@thumbnail Sticker thumbnail in WEBP or JPEG format; may be null @premium_animation Premium animation of the sticker; may be null. If present, only Premium users can send the sticker @sticker File containing the sticker
|
||||
sticker set_id:int64 width:int32 height:int32 emoji:string type:StickerType outline:vector<closedVectorPath> thumbnail:thumbnail premium_animation:file 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
|
||||
|
@ -245,6 +245,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
|
||||
string minithumbnail;
|
||||
PhotoSize thumbnail;
|
||||
AnimationSize animated_thumbnail;
|
||||
FileId premium_animation_file_id;
|
||||
FileEncryptionKey encryption_key;
|
||||
bool is_web = false;
|
||||
bool is_web_no_proxy = false;
|
||||
@ -310,11 +311,17 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
|
||||
}
|
||||
for (auto &thumb : document->video_thumbs_) {
|
||||
if (thumb->type_ == "v") {
|
||||
if (!animated_thumbnail.file_id.is_valid()) {
|
||||
animated_thumbnail =
|
||||
get_animation_size(td_->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Thumbnail, 0), id,
|
||||
access_hash, file_reference, DcId::create(dc_id), owner_dialog_id, std::move(thumb));
|
||||
if (animated_thumbnail.file_id.is_valid()) {
|
||||
break;
|
||||
}
|
||||
} else if (thumb->type_ == "f") {
|
||||
if (!premium_animation_file_id.is_valid()) {
|
||||
premium_animation_file_id =
|
||||
register_photo_size(td_->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Thumbnail, 'f'), id,
|
||||
access_hash, file_reference, owner_dialog_id, thumb->size_, DcId::create(dc_id),
|
||||
get_sticker_format_photo_format(sticker_format));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -478,8 +485,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
|
||||
if (thumbnail_format == PhotoFormat::Jpeg) {
|
||||
minithumbnail = string();
|
||||
}
|
||||
td_->stickers_manager_->create_sticker(file_id, std::move(minithumbnail), std::move(thumbnail), dimensions,
|
||||
std::move(sticker), sticker_format, load_data_multipromise_ptr);
|
||||
td_->stickers_manager_->create_sticker(file_id, premium_animation_file_id, std::move(minithumbnail),
|
||||
std::move(thumbnail), dimensions, std::move(sticker), sticker_format,
|
||||
load_data_multipromise_ptr);
|
||||
break;
|
||||
case Document::Type::Video:
|
||||
td_->videos_manager_->create_video(file_id, std::move(minithumbnail), std::move(thumbnail),
|
||||
|
@ -1234,7 +1234,7 @@ template <>
|
||||
tl_object_ptr<td_api::sticker> copy(const td_api::sticker &obj) {
|
||||
return td_api::make_object<td_api::sticker>(obj.set_id_, obj.width_, obj.height_, obj.emoji_, copy(obj.type_),
|
||||
transform(obj.outline_, copy_closed_vector_path), copy(obj.thumbnail_),
|
||||
copy(obj.sticker_));
|
||||
copy(obj.premium_animation_), copy(obj.sticker_));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -1823,7 +1823,7 @@ static Result<InputMessageContent> create_input_message_content(
|
||||
|
||||
emoji = std::move(input_sticker->emoji_);
|
||||
|
||||
td->stickers_manager_->create_sticker(file_id, string(), thumbnail,
|
||||
td->stickers_manager_->create_sticker(file_id, FileId(), string(), thumbnail,
|
||||
get_dimensions(input_sticker->width_, input_sticker->height_, nullptr),
|
||||
nullptr, StickerFormat::Unknown, nullptr);
|
||||
|
||||
|
@ -27,8 +27,8 @@ class FileManager;
|
||||
|
||||
struct PhotoSize {
|
||||
int32 type = 0;
|
||||
Dimensions dimensions;
|
||||
int32 size = 0;
|
||||
Dimensions dimensions;
|
||||
FileId file_id;
|
||||
vector<int32> progressive_sizes;
|
||||
};
|
||||
|
@ -88,6 +88,21 @@ Slice get_sticker_format_extension(StickerFormat sticker_format) {
|
||||
}
|
||||
}
|
||||
|
||||
PhotoFormat get_sticker_format_photo_format(StickerFormat sticker_format) {
|
||||
switch (sticker_format) {
|
||||
case StickerFormat::Unknown:
|
||||
case StickerFormat::Webp:
|
||||
return PhotoFormat::Webp;
|
||||
case StickerFormat::Tgs:
|
||||
return PhotoFormat::Tgs;
|
||||
case StickerFormat::Webm:
|
||||
return PhotoFormat::Webm;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return PhotoFormat::Webp;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_sticker_format_animated(StickerFormat sticker_format) {
|
||||
switch (sticker_format) {
|
||||
case StickerFormat::Unknown:
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/PhotoFormat.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
@ -28,6 +29,8 @@ string get_sticker_format_mime_type(StickerFormat sticker_format);
|
||||
|
||||
Slice get_sticker_format_extension(StickerFormat sticker_format);
|
||||
|
||||
PhotoFormat get_sticker_format_photo_format(StickerFormat sticker_format);
|
||||
|
||||
bool is_sticker_format_animated(StickerFormat sticker_format);
|
||||
|
||||
bool is_sticker_format_vector(StickerFormat sticker_format);
|
||||
|
@ -1872,11 +1872,14 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
|
||||
width = static_cast<int32>(width * zoom + 0.5);
|
||||
height = static_cast<int32>(height * zoom + 0.5);
|
||||
}
|
||||
return make_tl_object<td_api::sticker>(
|
||||
auto premium_animation_object = sticker->premium_animation_file_id.is_valid()
|
||||
? td_->file_manager_->get_file_object(sticker->premium_animation_file_id)
|
||||
: nullptr;
|
||||
return td_api::make_object<td_api::sticker>(
|
||||
sticker->set_id.get(), width, height, sticker->alt,
|
||||
get_sticker_type_object(sticker->format, sticker->is_mask, std::move(mask_position)),
|
||||
get_sticker_minithumbnail(sticker->minithumbnail, sticker->set_id, document_id, zoom),
|
||||
std::move(thumbnail_object), td_->file_manager_->get_file_object(file_id));
|
||||
std::move(thumbnail_object), std::move(premium_animation_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 {
|
||||
@ -2195,6 +2198,7 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
<< s->m_thumbnail << " to " << new_sticker->m_thumbnail;
|
||||
s->m_thumbnail = std::move(new_sticker->m_thumbnail);
|
||||
}
|
||||
s->premium_animation_file_id = new_sticker->premium_animation_file_id;
|
||||
if (s->format != new_sticker->format && new_sticker->format != StickerFormat::Unknown) {
|
||||
s->format = new_sticker->format;
|
||||
}
|
||||
@ -2290,6 +2294,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
|
||||
PhotoSize thumbnail;
|
||||
string minithumbnail;
|
||||
auto thumbnail_format = has_webp_thumbnail(document->thumbs_) ? PhotoFormat::Webp : PhotoFormat::Jpeg;
|
||||
FileId premium_animation_file_id;
|
||||
for (auto &thumb : document->thumbs_) {
|
||||
auto photo_size = get_photo_size(td_->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Thumbnail, 0),
|
||||
document_id, document->access_hash_, document->file_reference_.as_slice().str(),
|
||||
@ -2305,9 +2310,19 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &thumb : document->video_thumbs_) {
|
||||
if (thumb->type_ == "f") {
|
||||
if (!premium_animation_file_id.is_valid()) {
|
||||
premium_animation_file_id =
|
||||
register_photo_size(td_->file_manager_.get(), PhotoSizeSource::thumbnail(FileType::Thumbnail, 'f'),
|
||||
document_id, document->access_hash_, document->file_reference_.as_slice().str(),
|
||||
DialogId(), thumb->size_, dc_id, get_sticker_format_photo_format(format));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
create_sticker(sticker_id, std::move(minithumbnail), std::move(thumbnail), dimensions, std::move(sticker), format,
|
||||
nullptr);
|
||||
create_sticker(sticker_id, premium_animation_file_id, std::move(minithumbnail), std::move(thumbnail), dimensions,
|
||||
std::move(sticker), format, nullptr);
|
||||
return {document_id, sticker_id};
|
||||
}
|
||||
|
||||
@ -2448,6 +2463,9 @@ vector<FileId> StickersManager::get_sticker_file_ids(FileId file_id) const {
|
||||
if (sticker->m_thumbnail.file_id.is_valid()) {
|
||||
result.push_back(sticker->m_thumbnail.file_id);
|
||||
}
|
||||
if (sticker->premium_animation_file_id.is_valid()) {
|
||||
result.push_back(sticker->premium_animation_file_id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2458,7 +2476,7 @@ FileId StickersManager::dup_sticker(FileId new_id, FileId old_id) {
|
||||
CHECK(new_sticker == nullptr);
|
||||
new_sticker = make_unique<Sticker>(*old_sticker);
|
||||
new_sticker->file_id = new_id;
|
||||
// there is no reason to dup m_thumbnail
|
||||
// there is no reason to dup m_thumbnail and premium_animation_file_id
|
||||
new_sticker->s_thumbnail.file_id = td_->file_manager_->dup_file_id(new_sticker->s_thumbnail.file_id);
|
||||
return new_id;
|
||||
}
|
||||
@ -2624,7 +2642,8 @@ void StickersManager::add_sticker_thumbnail(Sticker *s, PhotoSize thumbnail) {
|
||||
LOG(ERROR) << "Receive sticker thumbnail of unsupported type " << thumbnail.type;
|
||||
}
|
||||
|
||||
void StickersManager::create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions,
|
||||
void StickersManager::create_sticker(FileId file_id, FileId premium_animation_file_id, string minithumbnail,
|
||||
PhotoSize thumbnail, Dimensions dimensions,
|
||||
tl_object_ptr<telegram_api::documentAttributeSticker> sticker,
|
||||
StickerFormat format, MultiPromiseActor *load_data_multipromise_ptr) {
|
||||
if (format == StickerFormat::Unknown && sticker == nullptr) {
|
||||
@ -2654,6 +2673,7 @@ void StickersManager::create_sticker(FileId file_id, string minithumbnail, Photo
|
||||
s->minithumbnail = std::move(minithumbnail);
|
||||
}
|
||||
add_sticker_thumbnail(s.get(), std::move(thumbnail));
|
||||
s->premium_animation_file_id = premium_animation_file_id;
|
||||
if (sticker != nullptr) {
|
||||
s->set_id = on_get_input_sticker_set(file_id, std::move(sticker->stickerset_), load_data_multipromise_ptr);
|
||||
s->alt = std::move(sticker->alt_);
|
||||
@ -5649,7 +5669,8 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
|
||||
|
||||
if (format == StickerFormat::Tgs) {
|
||||
int32 width = for_thumbnail ? 100 : 512;
|
||||
create_sticker(file_id, string(), PhotoSize(), get_dimensions(width, width, nullptr), nullptr, format, nullptr);
|
||||
create_sticker(file_id, FileId(), string(), PhotoSize(), get_dimensions(width, width, "prepare_input_file"),
|
||||
nullptr, format, nullptr);
|
||||
} else if (format == StickerFormat::Webm) {
|
||||
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.webm", "video/webm", false);
|
||||
} else {
|
||||
|
@ -94,9 +94,9 @@ class StickersManager final : public Actor {
|
||||
|
||||
bool is_active_reaction(const string &reaction) const;
|
||||
|
||||
void create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions,
|
||||
tl_object_ptr<telegram_api::documentAttributeSticker> sticker, StickerFormat sticker_format,
|
||||
MultiPromiseActor *load_data_multipromise_ptr);
|
||||
void create_sticker(FileId file_id, FileId premium_animation_file_id, string minithumbnail, PhotoSize thumbnail,
|
||||
Dimensions dimensions, tl_object_ptr<telegram_api::documentAttributeSticker> sticker,
|
||||
StickerFormat sticker_format, MultiPromiseActor *load_data_multipromise_ptr);
|
||||
|
||||
bool has_input_media(FileId sticker_file_id, bool is_secret) const;
|
||||
|
||||
@ -351,6 +351,7 @@ class StickersManager final : public Actor {
|
||||
string minithumbnail;
|
||||
PhotoSize s_thumbnail;
|
||||
PhotoSize m_thumbnail;
|
||||
FileId premium_animation_file_id;
|
||||
FileId file_id;
|
||||
StickerFormat format = StickerFormat::Unknown;
|
||||
bool is_mask = false;
|
||||
|
@ -33,6 +33,7 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
|
||||
bool has_minithumbnail = !sticker->minithumbnail.empty();
|
||||
bool is_tgs = sticker->format == StickerFormat::Tgs;
|
||||
bool is_webm = sticker->format == StickerFormat::Webm;
|
||||
bool has_premium_animation = sticker->premium_animation_file_id.is_valid();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(sticker->is_mask);
|
||||
STORE_FLAG(has_sticker_set_access_hash);
|
||||
@ -40,6 +41,7 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
|
||||
STORE_FLAG(is_tgs);
|
||||
STORE_FLAG(has_minithumbnail);
|
||||
STORE_FLAG(is_webm);
|
||||
STORE_FLAG(has_premium_animation);
|
||||
END_STORE_FLAGS();
|
||||
if (!in_sticker_set) {
|
||||
store(sticker->set_id.get(), storer);
|
||||
@ -63,6 +65,9 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
|
||||
if (has_minithumbnail) {
|
||||
store(sticker->minithumbnail, storer);
|
||||
}
|
||||
if (has_premium_animation) {
|
||||
store(sticker->premium_animation_file_id, storer);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
@ -77,6 +82,7 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
|
||||
bool has_minithumbnail;
|
||||
bool is_tgs;
|
||||
bool is_webm;
|
||||
bool has_premium_animation;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(sticker->is_mask);
|
||||
PARSE_FLAG(has_sticker_set_access_hash);
|
||||
@ -84,6 +90,7 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
|
||||
PARSE_FLAG(is_tgs);
|
||||
PARSE_FLAG(has_minithumbnail);
|
||||
PARSE_FLAG(is_webm);
|
||||
PARSE_FLAG(has_premium_animation);
|
||||
END_PARSE_FLAGS();
|
||||
if (is_webm) {
|
||||
sticker->format = StickerFormat::Webm;
|
||||
@ -133,6 +140,9 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
|
||||
if (has_minithumbnail) {
|
||||
parse(sticker->minithumbnail, parser);
|
||||
}
|
||||
if (has_premium_animation) {
|
||||
parse(sticker->premium_animation_file_id, parser);
|
||||
}
|
||||
if (parser.get_error() != nullptr || !sticker->file_id.is_valid()) {
|
||||
return FileId();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user