From 7e543cf80b44ab47652a4ea9be29cd7be8f463ab Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 21 Jun 2021 22:25:26 +0300 Subject: [PATCH] Allow to use uploadStickerFile for animated stickers. --- td/generate/scheme/td_api.tl | 7 +++---- td/telegram/StickersManager.cpp | 9 +++++++-- td/telegram/StickersManager.h | 2 +- td/telegram/Td.cpp | 9 ++++----- td/telegram/cli.cpp | 22 +++++++++++++++++----- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 074b7a6b9..16fd25ed2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5336,9 +5336,8 @@ checkPhoneNumberConfirmationCode code:string = Ok; setBotUpdatesStatus pending_update_count:int32 error_message:string = Ok; -//@description Uploads a PNG image with a sticker; for bots only; returns the uploaded file -//@user_id Sticker file owner @png_sticker PNG image with the sticker; must be up to 512 KB in size and fit in 512x512 square -uploadStickerFile user_id:int32 png_sticker:InputFile = File; +//@description Uploads a PNG image with a sticker; returns the uploaded file @user_id Sticker file owner; ignored for regular users @sticker Sticker file to upload +uploadStickerFile user_id:int32 sticker:InputSticker = File; //@description Returns a suggested name for a new sticker set with a given title @title Sticker set title; 1-64 characters getSuggestedStickerSetName title:string = Text; @@ -5351,7 +5350,7 @@ checkStickerSetName name:string = CheckStickerSetNameResult; //@title Sticker set title; 1-64 characters //@name Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_"* (** is case insensitive) for bots; 1-64 characters //@is_masks True, if stickers are masks. Animated stickers can't be masks -//@stickers List of stickers to be added to the set; must be non-empty. All stickers must be of the same type +//@stickers List of stickers to be added to the set; must be non-empty. All stickers must be of the same type. For animated stickers, uploadStickerFile must be used before the sticker is shown //@source Source of the sticker set; may be empty if unknown createNewStickerSet user_id:int32 title:string name:string is_masks:Bool stickers:vector source:string = StickerSet; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 2bd9bf32a..fd69b1628 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -4699,8 +4699,13 @@ Result> StickersManager::prepare_input_file return std::make_tuple(file_id, is_url, is_local, is_animated); } -FileId StickersManager::upload_sticker_file(UserId user_id, const tl_object_ptr &sticker, +FileId StickersManager::upload_sticker_file(UserId user_id, tl_object_ptr &&sticker, Promise &&promise) { + bool is_bot = td_->auth_manager_->is_bot(); + if (!is_bot) { + user_id = td_->contacts_manager_->get_my_id(); + } + auto input_user = td_->contacts_manager_->get_input_user(user_id); if (input_user == nullptr) { promise.set_error(Status::Error(3, "User not found")); @@ -4713,7 +4718,7 @@ FileId StickersManager::upload_sticker_file(UserId user_id, const tl_object_ptr< return FileId(); } - auto r_file_id = prepare_input_file(sticker, false, false); + auto r_file_id = prepare_input_sticker(sticker.get()); if (r_file_id.is_error()) { promise.set_error(r_file_id.move_as_error()); return FileId(); diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 039f38a90..5adb560b9 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -163,7 +163,7 @@ class StickersManager : public Actor { void reorder_installed_sticker_sets(bool is_masks, const vector &sticker_set_ids, Promise &&promise); - FileId upload_sticker_file(UserId user_id, const tl_object_ptr &sticker, Promise &&promise); + FileId upload_sticker_file(UserId user_id, tl_object_ptr &&sticker, Promise &&promise); void get_suggested_sticker_set_name(string short_name, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index bc463786b..48b7bb076 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2533,12 +2533,12 @@ class ChangeStickerSetRequest : public RequestOnceActor { class UploadStickerFileRequest : public RequestOnceActor { UserId user_id_; - tl_object_ptr sticker_; + tl_object_ptr sticker_; FileId file_id; void do_run(Promise &&promise) override { - file_id = td->stickers_manager_->upload_sticker_file(user_id_, sticker_, std::move(promise)); + file_id = td->stickers_manager_->upload_sticker_file(user_id_, std::move(sticker_), std::move(promise)); } void do_send_result() override { @@ -2547,7 +2547,7 @@ class UploadStickerFileRequest : public RequestOnceActor { public: UploadStickerFileRequest(ActorShared td, uint64 request_id, int32 user_id, - tl_object_ptr &&sticker) + tl_object_ptr &&sticker) : RequestOnceActor(std::move(td), request_id), user_id_(user_id), sticker_(std::move(sticker)) { } }; @@ -7036,8 +7036,7 @@ void Td::on_request(uint64 id, td_api::reorderInstalledStickerSets &request) { } void Td::on_request(uint64 id, td_api::uploadStickerFile &request) { - CHECK_IS_BOT(); - CREATE_REQUEST(UploadStickerFileRequest, request.user_id_, std::move(request.png_sticker_)); + CREATE_REQUEST(UploadStickerFileRequest, request.user_id_, std::move(request.sticker_)); } void Td::on_request(uint64 id, td_api::getSuggestedStickerSetName &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f6aa30ee1..feaa192ac 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2417,18 +2417,30 @@ class CliClient final : public Actor { } else if (op == "cssn") { string name = args; send_request(td_api::make_object(name)); - } else if (op == "cnss") { + } else if (op == "usf" || op == "usfa") { + td_api::object_ptr input_sticker; + if (op == "usfa") { + input_sticker = td_api::make_object(as_input_file(args), "😀"); + } else { + input_sticker = td_api::make_object(as_input_file(args), "😀", nullptr); + } + send_request(td_api::make_object(-1, std::move(input_sticker))); + } else if (op == "cnss" || op == "cnssa") { string title; string name; string stickers; get_args(args, title, name, stickers); auto input_stickers = transform(full_split(stickers, get_delimiter(stickers)), - [](string sticker) -> td_api::object_ptr { - return td_api::make_object(as_input_file(sticker), "😀", nullptr); + [op](string sticker) -> td_api::object_ptr { + if (op == "cnssa") { + return td_api::make_object(as_input_file(sticker), "😀"); + } else { + return td_api::make_object(as_input_file(sticker), "😀", nullptr); + } }); - send_request( - td_api::make_object(my_id_, title, name, false, std::move(input_stickers), "tg_cli")); + send_request(td_api::make_object(my_id_, title, name, false, + std::move(input_stickers), "tg_cli")); } else if (op == "sss") { send_request(td_api::make_object(args)); } else if (op == "siss") {