Add sticker cover to API.

This commit is contained in:
levlam 2020-11-20 16:22:07 +03:00
parent d22dabfdaf
commit 3ff1f6cec1
5 changed files with 41 additions and 4 deletions

View File

@ -270,8 +270,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 @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

Binary file not shown.

View File

@ -957,7 +957,7 @@ tl_object_ptr<td_api::photo> copy(const td_api::photo &obj) {
template <>
tl_object_ptr<td_api::sticker> copy(const td_api::sticker &obj) {
return make_tl_object<td_api::sticker>(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_));
}

View File

@ -1334,6 +1334,40 @@ tl_object_ptr<td_api::MaskPoint> StickersManager::get_mask_point_object(int32 po
}
}
string StickersManager::get_sticker_minithumbnail(const string &path) {
if (path.empty()) {
return string();
}
const auto prefix = Slice(
"<?xml version=\"1.0\" encoding=\"utf-8\"?><svg version=\"1.1\" id=\"Layer_1\" "
"xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" "
"viewBox=\"0 0 512 512\" style=\"enable-background:new 0 0 512 512;\" xml:space=\"preserve\"><style "
"type=\"text/css\">.st0{fill:#E8E8E8;}</style><path class=\"st0\" d=\"M");
const auto suffix = Slice("z\"/></svg>");
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<td_api::sticker> StickersManager::get_sticker_object(FileId file_id) const {
if (!file_id.is_valid()) {
return nullptr;
@ -1362,7 +1396,8 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
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),
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<td_api::stickers> StickersManager::get_stickers_object(const vector<FileId> &sticker_ids) const {

View File

@ -393,6 +393,8 @@ class StickersManager : public Actor {
class UploadStickerFileCallback;
static string get_sticker_minithumbnail(const string &path);
static tl_object_ptr<td_api::MaskPoint> get_mask_point_object(int32 point);
tl_object_ptr<td_api::stickerSetInfo> get_sticker_set_info_object(StickerSetId sticker_set_id,