From ae0a473cb9f3c16d5427ab32f607fb37396b46d5 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 10 Feb 2023 15:52:25 +0300 Subject: [PATCH] Add td_api::setStickerMaskPosition. --- td/generate/scheme/td_api.tl | 5 +++++ td/telegram/StickerMaskPosition.cpp | 3 ++- td/telegram/StickersManager.cpp | 27 ++++++++++++++++++--------- td/telegram/StickersManager.h | 3 +++ td/telegram/Td.cpp | 6 ++++++ td/telegram/Td.h | 2 ++ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a5849eec4..9db8dab80 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8030,6 +8030,11 @@ setStickerEmojis sticker:InputFile emojis:string = Ok; //@keywords List of up to 20 keywords with total length up to 64 characters, which can be used to find the sticker setStickerKeywords sticker:InputFile keywords:vector = Ok; +//@description Changes the mask position of a mask sticker; for bots only. The sticker must belong to a mask sticker set created by the bot +//@sticker Sticker +//@mask_position Position where the mask is placed; pass null to remove mask position +setStickerMaskPosition sticker:InputFile mask_position:maskPosition = Ok; + //@description Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded //@location Location of the map center diff --git a/td/telegram/StickerMaskPosition.cpp b/td/telegram/StickerMaskPosition.cpp index 02e64d40d..0e76cf807 100644 --- a/td/telegram/StickerMaskPosition.cpp +++ b/td/telegram/StickerMaskPosition.cpp @@ -60,7 +60,8 @@ StickerMaskPosition::StickerMaskPosition(const td_api::object_ptrx_shift_; - y_shift_ = mask_position->y_shift_, scale_ = mask_position->scale_; + y_shift_ = mask_position->y_shift_; + scale_ = mask_position->scale_; } telegram_api::object_ptr StickerMaskPosition::get_input_mask_coords() const { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 8e62915da..f72d49e77 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1395,8 +1395,7 @@ class ChangeStickerQuery final : public Td::ResultHandler { } void send(const string &short_name, tl_object_ptr &&input_document, bool edit_emojis, - const string &emojis, bool edit_mask_position, StickerMaskPosition mask_position, bool edit_keywords, - const string &keywords) { + const string &emojis, StickerMaskPosition mask_position, bool edit_keywords, const string &keywords) { vector chain_ids; if (!short_name.empty()) { chain_ids.emplace_back(short_name); @@ -1405,16 +1404,17 @@ class ChangeStickerQuery final : public Td::ResultHandler { if (edit_emojis) { flags |= telegram_api::stickers_changeSticker::EMOJI_MASK; } - if (edit_mask_position) { + auto mask_coords = mask_position.get_input_mask_coords(); + if (mask_coords != nullptr) { flags |= telegram_api::stickers_changeSticker::MASK_COORDS_MASK; } if (edit_keywords) { flags |= telegram_api::stickers_changeSticker::KEYWORDS_MASK; } - send_query(G()->net_query_creator().create( - telegram_api::stickers_changeSticker(flags, std::move(input_document), emojis, - mask_position.get_input_mask_coords(), keywords), - std::move(chain_ids))); + send_query( + G()->net_query_creator().create(telegram_api::stickers_changeSticker(flags, std::move(input_document), emojis, + std::move(mask_coords), keywords), + std::move(chain_ids))); } void on_result(BufferSlice packet) final { @@ -8719,7 +8719,7 @@ void StickersManager::set_sticker_emojis(const td_api::object_ptrcreate_handler(std::move(promise)) - ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), true, emojis, false, + ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), true, emojis, StickerMaskPosition(), false, string()); } @@ -8735,10 +8735,19 @@ void StickersManager::set_sticker_keywords(const td_api::object_ptrcreate_handler(std::move(promise)) - ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), false, string(), false, + ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), false, string(), StickerMaskPosition(), true, implode(keywords, ',')); } +void StickersManager::set_sticker_mask_position(const td_api::object_ptr &sticker, + td_api::object_ptr &&mask_position, + Promise &&promise) { + TRY_RESULT_PROMISE(promise, input_document, get_sticker_input_document(sticker)); + td_->create_handler(std::move(promise)) + ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), false, string(), + StickerMaskPosition(mask_position), false, string()); +} + vector StickersManager::get_attached_sticker_file_ids(const vector &int_file_ids) { vector result; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index f89ed2fa7..9769d92a8 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -324,6 +324,9 @@ class StickersManager final : public Actor { void set_sticker_keywords(const td_api::object_ptr &sticker, vector &&keywords, Promise &&promise); + void set_sticker_mask_position(const td_api::object_ptr &sticker, + td_api::object_ptr &&mask_position, Promise &&promise); + vector get_recent_stickers(bool is_attached, Promise &&promise); void on_get_recent_stickers(bool is_repair, bool is_attached, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index afa2a0856..0fad504fb 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7354,6 +7354,12 @@ void Td::on_request(uint64 id, td_api::setStickerKeywords &request) { stickers_manager_->set_sticker_keywords(request.sticker_, std::move(request.keywords_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::setStickerMaskPosition &request) { + CHECK_IS_BOT(); + CREATE_OK_REQUEST_PROMISE(); + stickers_manager_->set_sticker_mask_position(request.sticker_, std::move(request.mask_position_), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getRecentStickers &request) { CHECK_IS_USER(); CREATE_REQUEST(GetRecentStickersRequest, request.is_attached_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c522cb9cd..8b86e191f 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1212,6 +1212,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setStickerKeywords &request); + void on_request(uint64 id, td_api::setStickerMaskPosition &request); + void on_request(uint64 id, const td_api::getRecentStickers &request); void on_request(uint64 id, td_api::addRecentSticker &request);