From 79f18906132d7d6b43f210de6e1d5050af5b51f4 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jan 2022 17:53:38 +0300 Subject: [PATCH] Use td_api::StickerType instead of td_api::StickerFormat. --- td/generate/scheme/td_api.tl | 32 ++++++++++++++-------------- td/telegram/InlineQueriesManager.cpp | 22 +++++++++---------- td/telegram/StickerFormat.cpp | 12 +++++------ td/telegram/StickerFormat.h | 4 ++-- td/telegram/StickersManager.cpp | 28 ++++++++++++------------ td/telegram/cli.cpp | 24 ++++++++++----------- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 582392e9c..852de5f9f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -240,19 +240,19 @@ maskPointChin = MaskPoint; maskPosition point:MaskPoint x_shift:double y_shift:double scale:double = MaskPosition; -//@class StickerFormat @description Describes format of a sticker +//@class StickerType @description Describes type of a sticker -//@description The sticker is in TGS format -stickerFormatTgs = StickerFormat; +//@description The sticker is an image in WEBP format +stickerTypeStatic = StickerType; -//@description The sticker is in WEBM format -stickerFormatWebm = StickerFormat; +//@description The sticker is an animation in TGS format +stickerTypeAnimated = StickerType; -//@description The sticker is in WEBP format -stickerFormatWebp = StickerFormat; +//@description The sticker is a video in WEBM format +stickerTypeVideo = StickerType; //@description The sticker is a mask in WEBP format to be placed on photos or videos @mask_position Position where the mask is placed; may be null -stickerFormatWebpMask mask_position:maskPosition = StickerFormat; +stickerTypeMask mask_position:maskPosition = StickerType; //@description Represents a closed vector path. The path begins at the end point of the last command @commands List of vector path commands @@ -295,9 +295,9 @@ document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector = 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 @format Sticker format @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 +//@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 format:StickerFormat outline:vector thumbnail:thumbnail sticker:file = Sticker; +sticker set_id:int64 width:int32 height:int32 emoji:string type:StickerType outline:vector 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 @@ -2194,17 +2194,17 @@ emojis emojis:vector = Emojis; //@id Identifier of the sticker set @title Title of the sticker set @name Name of the sticker set @thumbnail Sticker set thumbnail in WEBP, TGS, or WEBM format with width and height 100; may be null. The file can be downloaded only before the thumbnail is changed //@thumbnail_outline Sticker set thumbnail's outline represented as a list of closed vector paths; may be empty. The coordinate system origin is in the upper-left corner //@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 @sticker_format Format of the stickers in the set @is_viewed True for already viewed trending sticker sets +//@is_official True, if the sticker set is official @sticker_type Type of the stickers in the set @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:thumbnail thumbnail_outline:vector is_installed:Bool is_archived:Bool is_official:Bool sticker_format:StickerFormat is_viewed:Bool stickers:vector emojis:vector = StickerSet; +stickerSet id:int64 title:string name:string thumbnail:thumbnail thumbnail_outline:vector is_installed:Bool is_archived:Bool is_official:Bool sticker_type:StickerType is_viewed:Bool stickers:vector emojis:vector = 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, TGS, or WEBM format with width and height 100; may be null //@thumbnail_outline Sticker set thumbnail's outline represented as a list of closed vector paths; may be empty. The coordinate system origin is in the upper-left corner //@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 @sticker_format Format of the stickers in the set @is_viewed True for already viewed trending sticker sets +//@is_official True, if the sticker set is official @sticker_type Type of the stickers in the set @is_viewed True for already viewed trending sticker sets //@size Total number of stickers in the set @covers Up to the first 5 stickers from the set, depending on the context. If the application needs more stickers the full sticker set needs to be requested -stickerSetInfo id:int64 title:string name:string thumbnail:thumbnail thumbnail_outline:vector is_installed:Bool is_archived:Bool is_official:Bool sticker_format:StickerFormat is_viewed:Bool size:int32 covers:vector = StickerSetInfo; +stickerSetInfo id:int64 title:string name:string thumbnail:thumbnail thumbnail_outline:vector is_installed:Bool is_archived:Bool is_official:Bool sticker_type:StickerType is_viewed:Bool size:int32 covers:vector = 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 = StickerSets; @@ -3585,8 +3585,8 @@ proxies proxies:vector = Proxies; //@description A sticker to be added to a sticker set //@sticker File with the sticker; must fit in a 512x512 square. For WEBP stickers and masks the file must be in PNG format, which will be converted to WEBP server-side. Otherwise, the file must be local or uploaded within a week. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements //@emojis Emojis corresponding to the sticker -//@format Sticker format -inputSticker sticker:InputFile emojis:string format:StickerFormat = InputSticker; +//@type Sticker type +inputSticker sticker:InputFile emojis:string type:StickerType = InputSticker; //@description Represents a date range @start_date Point in time (Unix timestamp) at which the date range begins @end_date Point in time (Unix timestamp) at which the date range ends diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index e134fe4eb..ea9dd3d66 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -998,17 +998,17 @@ tl_object_ptr copy(const td_api::maskPosition &obj) { } template <> -tl_object_ptr copy(const td_api::StickerFormat &obj) { +tl_object_ptr copy(const td_api::StickerType &obj) { switch (obj.get_id()) { - case td_api::stickerFormatWebp::ID: - return td_api::make_object(); - case td_api::stickerFormatTgs::ID: - return td_api::make_object(); - case td_api::stickerFormatWebm::ID: - return td_api::make_object(); - case td_api::stickerFormatWebpMask::ID: { - auto &mask_position = static_cast(obj).mask_position_; - return td_api::make_object(copy(mask_position)); + case td_api::stickerTypeStatic::ID: + return td_api::make_object(); + case td_api::stickerTypeAnimated::ID: + return td_api::make_object(); + case td_api::stickerTypeVideo::ID: + return td_api::make_object(); + case td_api::stickerTypeMask::ID: { + auto &mask_position = static_cast(obj).mask_position_; + return td_api::make_object(copy(mask_position)); } default: UNREACHABLE(); @@ -1082,7 +1082,7 @@ tl_object_ptr copy(const td_api::photo &obj) { template <> tl_object_ptr copy(const td_api::sticker &obj) { - return td_api::make_object(obj.set_id_, obj.width_, obj.height_, obj.emoji_, copy(obj.format_), + return td_api::make_object(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_)); } diff --git a/td/telegram/StickerFormat.cpp b/td/telegram/StickerFormat.cpp index 953612c13..1efb482c6 100644 --- a/td/telegram/StickerFormat.cpp +++ b/td/telegram/StickerFormat.cpp @@ -23,21 +23,21 @@ StickerFormat get_sticker_format(Slice mime_type) { return StickerFormat::Unknown; } -td_api::object_ptr get_sticker_format_object( +td_api::object_ptr get_sticker_type_object( StickerFormat sticker_format, bool is_masks, td_api::object_ptr mask_position) { switch (sticker_format) { case StickerFormat::Unknown: LOG(ERROR) << "Have a sticker of unknown format"; - return td_api::make_object(); + return td_api::make_object(); case StickerFormat::Webp: if (is_masks) { - return td_api::make_object(std::move(mask_position)); + return td_api::make_object(std::move(mask_position)); } - return td_api::make_object(); + return td_api::make_object(); case StickerFormat::Tgs: - return td_api::make_object(); + return td_api::make_object(); case StickerFormat::Webm: - return td_api::make_object(); + return td_api::make_object(); default: UNREACHABLE(); return nullptr; diff --git a/td/telegram/StickerFormat.h b/td/telegram/StickerFormat.h index 73a7ff9bf..8d4edbd31 100644 --- a/td/telegram/StickerFormat.h +++ b/td/telegram/StickerFormat.h @@ -19,8 +19,8 @@ enum class StickerFormat : int32 { Unknown, Webp, Tgs, Webm }; StickerFormat get_sticker_format(Slice mime_type); -td_api::object_ptr get_sticker_format_object( - StickerFormat sticker_format, bool is_masks, td_api::object_ptr mask_position); +td_api::object_ptr get_sticker_type_object(StickerFormat sticker_format, bool is_masks, + td_api::object_ptr mask_position); string get_sticker_format_mime_type(StickerFormat sticker_format); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 7b3a711ed..da36efcdf 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1852,7 +1852,7 @@ tl_object_ptr StickersManager::get_sticker_object(FileId file_i } return make_tl_object( sticker->set_id.get(), width, height, sticker->alt, - get_sticker_format_object(sticker->format, sticker->is_mask, std::move(mask_position)), + 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)); } @@ -1976,7 +1976,7 @@ tl_object_ptr StickersManager::get_sticker_set_object(Sticke sticker_set->id.get(), sticker_set->title, sticker_set->short_name, std::move(thumbnail), get_sticker_minithumbnail(sticker_set->minithumbnail, sticker_set->id, -2, 1.0), sticker_set->is_installed && !sticker_set->is_archived, sticker_set->is_archived, sticker_set->is_official, - get_sticker_format_object(sticker_set->sticker_format, sticker_set->is_masks, nullptr), sticker_set->is_viewed, + get_sticker_type_object(sticker_set->sticker_format, sticker_set->is_masks, nullptr), sticker_set->is_viewed, std::move(stickers), std::move(emojis)); } @@ -2023,7 +2023,7 @@ tl_object_ptr StickersManager::get_sticker_set_info_obje sticker_set->id.get(), sticker_set->title, sticker_set->short_name, std::move(thumbnail), get_sticker_minithumbnail(sticker_set->minithumbnail, sticker_set->id, -3, 1.0), sticker_set->is_installed && !sticker_set->is_archived, sticker_set->is_archived, sticker_set->is_official, - get_sticker_format_object(sticker_set->sticker_format, sticker_set->is_masks, nullptr), sticker_set->is_viewed, + get_sticker_type_object(sticker_set->sticker_format, sticker_set->is_masks, nullptr), sticker_set->is_viewed, sticker_set->was_loaded ? narrow_cast(sticker_set->sticker_ids.size()) : sticker_set->sticker_count, std::move(stickers)); } @@ -5563,18 +5563,18 @@ Result> StickersManager::prepare_i return Status::Error(400, "Emojis must be encoded in UTF-8"); } - if (sticker->format_ == nullptr) { - return Status::Error(400, "Sticker format must be non-empty"); + if (sticker->type_ == nullptr) { + return Status::Error(400, "Sticker type must be non-empty"); } - switch (sticker->format_->get_id()) { - case td_api::stickerFormatWebp::ID: + switch (sticker->type_->get_id()) { + case td_api::stickerTypeStatic::ID: return prepare_input_file(sticker->sticker_, StickerFormat::Webp, false); - case td_api::stickerFormatTgs::ID: + case td_api::stickerTypeAnimated::ID: return prepare_input_file(sticker->sticker_, StickerFormat::Tgs, false); - case td_api::stickerFormatWebm::ID: + case td_api::stickerTypeVideo::ID: return prepare_input_file(sticker->sticker_, StickerFormat::Webm, false); - case td_api::stickerFormatWebpMask::ID: + case td_api::stickerTypeMask::ID: return prepare_input_file(sticker->sticker_, StickerFormat::Webp, false); default: UNREACHABLE(); @@ -5670,8 +5670,8 @@ tl_object_ptr StickersManager::get_input_stic auto input_document = file_view.main_remote_location().as_input_document(); tl_object_ptr mask_coords; - if (sticker->format_->get_id() == td_api::stickerFormatWebpMask::ID) { - auto sticker_format = static_cast(sticker->format_.get()); + if (sticker->type_->get_id() == td_api::stickerTypeMask::ID) { + auto sticker_format = static_cast(sticker->type_.get()); auto mask_position = sticker_format->mask_position_.get(); if (mask_position != nullptr && mask_position->point_ != nullptr) { auto point = [mask_point_id = mask_position->point_->get_id()] { @@ -5792,7 +5792,7 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri if (is_sticker_format_animated(sticker_format) && is_url) { return promise.set_error(Status::Error(400, "Animated stickers can't be uploaded by URL")); } - sticker_formats.insert(sticker->format_->get_id()); + sticker_formats.insert(sticker->type_->get_id()); file_ids.push_back(file_id); if (is_url) { @@ -5976,7 +5976,7 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result res auto &promise = pending_new_sticker_set->promise; TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id)); - bool is_masks = pending_new_sticker_set->stickers[0]->format_->get_id() == td_api::stickerFormatWebpMask::ID; + bool is_masks = pending_new_sticker_set->stickers[0]->type_->get_id() == td_api::stickerTypeMask::ID; StickerFormat sticker_format = pending_new_sticker_set->sticker_format; auto sticker_count = pending_new_sticker_set->stickers.size(); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 37debbf79..bdcb4f585 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -527,19 +527,19 @@ class CliClient final : public Actor { return to_integer(trim(str)); } - static td_api::object_ptr as_sticker_format(string sticker_format) { - if (!sticker_format.empty() && sticker_format.back() == 't') { - return td_api::make_object(); + static td_api::object_ptr as_sticker_type(string sticker_type) { + if (!sticker_type.empty() && sticker_type.back() == 'a') { + return td_api::make_object(); } - if (!sticker_format.empty() && sticker_format.back() == 'w') { - return td_api::make_object(); + if (!sticker_type.empty() && sticker_type.back() == 'v') { + return td_api::make_object(); } - if (!sticker_format.empty() && sticker_format.back() == 'm') { + if (!sticker_type.empty() && sticker_type.back() == 'm') { auto position = td_api::make_object(td_api::make_object(), Random::fast(-5, 5), Random::fast(-5, 5), 1.0); - return td_api::make_object(Random::fast_bool() ? nullptr : std::move(position)); + return td_api::make_object(Random::fast_bool() ? nullptr : std::move(position)); } - return td_api::make_object(); + return td_api::make_object(); } static int32 as_limit(Slice str, int32 default_limit = 10) { @@ -2579,17 +2579,17 @@ class CliClient final : public Actor { } else if (op == "cssn") { const string &name = args; send_request(td_api::make_object(name)); - } else if (op == "usf" || op == "usft" || op == "usfw" || op == "usfm") { + } else if (op == "usf" || op == "usfa" || op == "usfv" || op == "usfm") { send_request(td_api::make_object( - -1, td_api::make_object(as_input_file(args), "😀", as_sticker_format(op)))); - } else if (op == "cnss" || op == "cnsst" || op == "cnssw" || op == "cnssm") { + -1, td_api::make_object(as_input_file(args), "😀", as_sticker_type(op)))); + } else if (op == "cnss" || op == "cnssa" || op == "cnssv" || op == "cnssm") { string title; string name; string stickers; get_args(args, title, name, stickers); auto input_stickers = transform(autosplit(stickers), [op](Slice sticker) -> td_api::object_ptr { - return td_api::make_object(as_input_file(sticker), "😀", as_sticker_format(op)); + return td_api::make_object(as_input_file(sticker), "😀", as_sticker_type(op)); }); send_request( td_api::make_object(my_id_, title, name, std::move(input_stickers), "tg_cli"));