From 3ff1f6cec195e5fc278f5db8a4548fd69333f575 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 20 Nov 2020 16:22:07 +0300 Subject: [PATCH] Add sticker cover to API. --- td/generate/scheme/td_api.tl | 4 +-- td/generate/scheme/td_api.tlo | Bin 185276 -> 185308 bytes td/telegram/InlineQueriesManager.cpp | 2 +- td/telegram/StickersManager.cpp | 37 ++++++++++++++++++++++++++- td/telegram/StickersManager.h | 2 ++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0b0292236..0771082d7 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -270,8 +270,8 @@ photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector = 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 @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; +//@cover Sticker cover in an SVG format; may be empty @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 cover:string 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 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 9379f8423d0c402634a64468d158bb80aa85aa81..825cc0800680de63f9e32c4704a4ac41b8e6fe7a 100644 GIT binary patch delta 287 zcmdn9ocqpl?hOqZJb&Jr^son)WF}{)7EL@Lv3ZHcjcOK<;N*rS2`V54BLf6TKfABV znv+_VS_I*9*tQ)6D`Z)!0MVfVWB5QBn+uk9NI~R2>{8e)bKplXm^VE@kWpc~g$U!5 zEHHn&LOtUKMNzO@iXm#JGWx73|!}3%^NER#+jjonr~(3r2{2UzRd{fyhojD9$9moo6|tMg~Oc Z0XLJ(^c)dJf$0{aj4InZ_?b+O003m+d7S_N delta 274 zcmcb!oO{o5?hOqZJpBjuU1JX}$xO~pEt+^hV)GJ>8`Ufz!O0Cv5>!A8Mg|Cwes*7z zH7B(!wFtuJux&dCR>-nc0ir_##_)kMHWw`Ikb=m4*rl*p=D?3&FmHN*Afv)|3lYXA zSz!Klg?h#filSh*6hqtsV&6O_ copy(const td_api::photo &obj) { template <> tl_object_ptr copy(const td_api::sticker &obj) { return make_tl_object(obj.set_id_, obj.width_, obj.height_, obj.emoji_, obj.is_animated_, - obj.is_mask_, copy(obj.mask_position_), copy(obj.thumbnail_), + obj.is_mask_, copy(obj.mask_position_), obj.cover_, copy(obj.thumbnail_), copy(obj.sticker_)); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 32fac339e..2e93cdf86 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1334,6 +1334,40 @@ tl_object_ptr StickersManager::get_mask_point_object(int32 po } } +string StickersManager::get_sticker_minithumbnail(const string &path) { + if (path.empty()) { + return string(); + } + + const auto prefix = Slice( + ""); + + auto buf = StackAllocator::alloc(1 << 7); + StringBuilder sb(buf.as_slice(), true); + + sb << prefix; + for (unsigned char c : path) { + if (c >= 128 + 64) { + sb << "AACAAAAHAAALMAAAQASTAVAAAZaacaaaahaaalmaaaqastava.az0123456789-,"[c - 128 - 64]; + } else { + if (c >= 128) { + sb << ','; + } else if (c >= 64) { + sb << '-'; + } + sb << (c & 63); + } + } + sb << suffix; + + CHECK(!sb.is_error()); + return sb.as_cslice().str(); +} + tl_object_ptr StickersManager::get_sticker_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; @@ -1362,7 +1396,8 @@ tl_object_ptr StickersManager::get_sticker_object(FileId file_i auto thumbnail_object = get_thumbnail_object(td_->file_manager_.get(), thumbnail, thumbnail_format); return make_tl_object(sticker->set_id.get(), sticker->dimensions.width, sticker->dimensions.height, sticker->alt, sticker->is_animated, sticker->is_mask, std::move(mask_position), - std::move(thumbnail_object), td_->file_manager_->get_file_object(file_id)); + get_sticker_minithumbnail(sticker->minithumbnail), std::move(thumbnail_object), + td_->file_manager_->get_file_object(file_id)); } tl_object_ptr StickersManager::get_stickers_object(const vector &sticker_ids) const { diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 7e4ec1254..ae4032d29 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -393,6 +393,8 @@ class StickersManager : public Actor { class UploadStickerFileCallback; + static string get_sticker_minithumbnail(const string &path); + static tl_object_ptr get_mask_point_object(int32 point); tl_object_ptr get_sticker_set_info_object(StickerSetId sticker_set_id,