Allow to use uploadStickerFile for animated stickers.

This commit is contained in:
levlam 2021-06-21 22:25:26 +03:00
parent 337dbc86d9
commit 7e543cf80b
5 changed files with 32 additions and 17 deletions

View File

@ -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_<bot username>"* (*<bot_username>* 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<InputSticker> source:string = StickerSet;

View File

@ -4699,8 +4699,13 @@ Result<std::tuple<FileId, bool, bool, bool>> 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<td_api::InputFile> &sticker,
FileId StickersManager::upload_sticker_file(UserId user_id, tl_object_ptr<td_api::InputSticker> &&sticker,
Promise<Unit> &&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();

View File

@ -163,7 +163,7 @@ class StickersManager : public Actor {
void reorder_installed_sticker_sets(bool is_masks, const vector<StickerSetId> &sticker_set_ids,
Promise<Unit> &&promise);
FileId upload_sticker_file(UserId user_id, const tl_object_ptr<td_api::InputFile> &sticker, Promise<Unit> &&promise);
FileId upload_sticker_file(UserId user_id, tl_object_ptr<td_api::InputSticker> &&sticker, Promise<Unit> &&promise);
void get_suggested_sticker_set_name(string short_name, Promise<string> &&promise);

View File

@ -2533,12 +2533,12 @@ class ChangeStickerSetRequest : public RequestOnceActor {
class UploadStickerFileRequest : public RequestOnceActor {
UserId user_id_;
tl_object_ptr<td_api::InputFile> sticker_;
tl_object_ptr<td_api::InputSticker> sticker_;
FileId file_id;
void do_run(Promise<Unit> &&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> td, uint64 request_id, int32 user_id,
tl_object_ptr<td_api::InputFile> &&sticker)
tl_object_ptr<td_api::InputSticker> &&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) {

View File

@ -2417,18 +2417,30 @@ class CliClient final : public Actor {
} else if (op == "cssn") {
string name = args;
send_request(td_api::make_object<td_api::checkStickerSetName>(name));
} else if (op == "cnss") {
} else if (op == "usf" || op == "usfa") {
td_api::object_ptr<td_api::InputSticker> input_sticker;
if (op == "usfa") {
input_sticker = td_api::make_object<td_api::inputStickerAnimated>(as_input_file(args), "😀");
} else {
input_sticker = td_api::make_object<td_api::inputStickerStatic>(as_input_file(args), "😀", nullptr);
}
send_request(td_api::make_object<td_api::uploadStickerFile>(-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<td_api::InputSticker> {
[op](string sticker) -> td_api::object_ptr<td_api::InputSticker> {
if (op == "cnssa") {
return td_api::make_object<td_api::inputStickerAnimated>(as_input_file(sticker), "😀");
} else {
return td_api::make_object<td_api::inputStickerStatic>(as_input_file(sticker), "😀", nullptr);
}
});
send_request(
td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, false, std::move(input_stickers), "tg_cli"));
send_request(td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, false,
std::move(input_stickers), "tg_cli"));
} else if (op == "sss") {
send_request(td_api::make_object<td_api::searchStickerSet>(args));
} else if (op == "siss") {