Move sticker_format to inputSticker.

This commit is contained in:
levlam 2024-03-15 21:08:30 +03:00
parent ce124d1a40
commit 9c7e0f6b22
5 changed files with 36 additions and 39 deletions

View File

@ -6309,10 +6309,11 @@ proxies proxies:vector<proxy> = 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 the file must be in WEBP or PNG format, which will be converted to WEBP server-side.
//-See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
//@format Format of the sticker
//@emojis String with 1-20 emoji corresponding to the sticker
//@mask_position Position where the mask is placed; pass null if not specified
//@keywords List of up to 20 keywords with total length up to 64 characters, which can be used to find the sticker
inputSticker sticker:InputFile emojis:string mask_position:maskPosition keywords:vector<string> = InputSticker;
inputSticker sticker:InputFile format:StickerFormat emojis:string mask_position:maskPosition keywords:vector<string> = 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
@ -10069,13 +10070,11 @@ checkStickerSetName name:string = CheckStickerSetNameResult;
//@user_id Sticker set owner; ignored for regular users
//@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
//@sticker_format Format of the stickers in the set
//@sticker_type Type of the stickers in the set
//@needs_repainting Pass true if stickers in the sticker set must be repainted; for custom emoji sticker sets only
//@stickers List of stickers to be added to the set; must be non-empty. All stickers must have the same format. For TGS stickers, uploadStickerFile must be used before the sticker is shown
//@source Source of the sticker set; may be empty if unknown
createNewStickerSet user_id:int53 title:string name:string sticker_format:StickerFormat sticker_type:StickerType needs_repainting:Bool stickers:vector<inputSticker> source:string = StickerSet;
createNewStickerSet user_id:int53 title:string name:string sticker_type:StickerType needs_repainting:Bool stickers:vector<inputSticker> source:string = StickerSet;
//@description Adds a new sticker to a set; for bots only
//@user_id Sticker set owner
@ -10086,8 +10085,9 @@ addStickerToSet user_id:int53 name:string sticker:inputSticker = Ok;
//@description Sets a sticker set thumbnail; for bots only
//@user_id Sticker set owner
//@name Sticker set name
//@thumbnail Thumbnail to set in PNG, TGS, or WEBM format; pass null to remove the sticker set thumbnail. Thumbnail format must match the format of stickers in the set
setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile = Ok;
//@thumbnail Thumbnail to set; pass null to remove the sticker set thumbnail
//@format Format of the thumbnail; pass null if thumbnail is removed
setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile format:StickerFormat = Ok;
//@description Sets a custom emoji sticker set thumbnail; for bots only
//@name Sticker set name

View File

@ -7712,7 +7712,6 @@ void StickersManager::move_sticker_set_to_top_by_custom_emoji_ids(const vector<C
}
Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_sticker(td_api::inputSticker *sticker,
StickerFormat sticker_format,
StickerType sticker_type) {
if (sticker == nullptr) {
return Status::Error(400, "Input sticker must be non-empty");
@ -7733,7 +7732,7 @@ Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_sticker(td
}
}
return prepare_input_file(sticker->sticker_, sticker_format, sticker_type, false);
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), sticker_type, false);
}
Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_file(
@ -7898,8 +7897,7 @@ td_api::object_ptr<td_api::CheckStickerSetNameResult> StickersManager::get_check
}
}
void StickersManager::create_new_sticker_set(UserId user_id, string title, string short_name,
StickerFormat sticker_format, StickerType sticker_type,
void StickersManager::create_new_sticker_set(UserId user_id, string title, string short_name, StickerType sticker_type,
bool has_text_color,
vector<td_api::object_ptr<td_api::inputSticker>> &&stickers,
string software,
@ -7934,7 +7932,7 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin
vector<FileId> local_file_ids;
vector<FileId> url_file_ids;
for (auto &sticker : stickers) {
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_format, sticker_type);
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_type);
if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error());
}
@ -7954,7 +7952,6 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin
pending_new_sticker_set->user_id_ = user_id;
pending_new_sticker_set->title_ = std::move(title);
pending_new_sticker_set->short_name_ = short_name;
pending_new_sticker_set->sticker_format_ = sticker_format;
pending_new_sticker_set->sticker_type_ = sticker_type;
pending_new_sticker_set->has_text_color_ = has_text_color;
pending_new_sticker_set->file_ids_ = std::move(file_ids);
@ -8199,7 +8196,7 @@ void StickersManager::do_add_sticker_to_set(UserId user_id, string short_name,
return promise.set_error(Status::Error(400, "Sticker set not found"));
}
auto r_file_id = prepare_input_sticker(sticker.get(), StickerFormat::Webp, sticker_set->sticker_type_);
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_set->sticker_type_);
if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error());
}
@ -8254,7 +8251,8 @@ void StickersManager::on_added_sticker_uploaded(int64 random_id, Result<Unit> re
}
void StickersManager::set_sticker_set_thumbnail(UserId user_id, string short_name,
tl_object_ptr<td_api::InputFile> &&thumbnail, Promise<Unit> &&promise) {
td_api::object_ptr<td_api::InputFile> &&thumbnail, StickerFormat format,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id));
short_name = clean_username(strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH));
@ -8264,26 +8262,26 @@ void StickersManager::set_sticker_set_thumbnail(UserId user_id, string short_nam
const StickerSet *sticker_set = get_sticker_set(short_name_to_sticker_set_id_.get(short_name));
if (sticker_set != nullptr && sticker_set->was_loaded_) {
return do_set_sticker_set_thumbnail(user_id, short_name, std::move(thumbnail), std::move(promise));
return do_set_sticker_set_thumbnail(user_id, short_name, std::move(thumbnail), format, std::move(promise));
}
do_reload_sticker_set(
StickerSetId(), make_tl_object<telegram_api::inputStickerSetShortName>(short_name), 0,
PromiseCreator::lambda([actor_id = actor_id(this), user_id, short_name, thumbnail = std::move(thumbnail),
PromiseCreator::lambda([actor_id = actor_id(this), user_id, short_name, thumbnail = std::move(thumbnail), format,
promise = std::move(promise)](Result<Unit> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &StickersManager::do_set_sticker_set_thumbnail, user_id, std::move(short_name),
std::move(thumbnail), std::move(promise));
std::move(thumbnail), format, std::move(promise));
}
}),
"set_sticker_set_thumbnail");
}
void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_name,
tl_object_ptr<td_api::InputFile> &&thumbnail,
Promise<Unit> &&promise) {
td_api::object_ptr<td_api::InputFile> &&thumbnail,
StickerFormat format, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
const StickerSet *sticker_set = get_sticker_set(short_name_to_sticker_set_id_.get(short_name));
@ -8295,7 +8293,7 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_
Status::Error(400, "The method can't be used to set thumbnail of custom emoji sticker sets"));
}
auto r_file_id = prepare_input_file(thumbnail, StickerFormat::Webp, sticker_set->sticker_type_, true);
auto r_file_id = prepare_input_file(thumbnail, format, sticker_set->sticker_type_, true);
if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error());
}

View File

@ -289,16 +289,15 @@ class StickersManager final : public Actor {
static td_api::object_ptr<td_api::CheckStickerSetNameResult> get_check_sticker_set_name_result_object(
CheckStickerSetNameResult result);
void create_new_sticker_set(UserId user_id, string title, string short_name, StickerFormat sticker_format,
StickerType sticker_type, bool has_text_color,
vector<td_api::object_ptr<td_api::inputSticker>> &&stickers, string software,
Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
void create_new_sticker_set(UserId user_id, string title, string short_name, StickerType sticker_type,
bool has_text_color, vector<td_api::object_ptr<td_api::inputSticker>> &&stickers,
string software, Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
void add_sticker_to_set(UserId user_id, string short_name, td_api::object_ptr<td_api::inputSticker> &&sticker,
Promise<Unit> &&promise);
void set_sticker_set_thumbnail(UserId user_id, string short_name, tl_object_ptr<td_api::InputFile> &&thumbnail,
Promise<Unit> &&promise);
void set_sticker_set_thumbnail(UserId user_id, string short_name, td_api::object_ptr<td_api::InputFile> &&thumbnail,
StickerFormat format, Promise<Unit> &&promise);
void set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise);
@ -520,7 +519,6 @@ class StickersManager final : public Actor {
string title_;
string short_name_;
StickerType sticker_type_ = StickerType::Regular;
StickerFormat sticker_format_ = StickerFormat::Unknown;
bool has_text_color_ = false;
vector<FileId> file_ids_;
vector<tl_object_ptr<td_api::inputSticker>> stickers_;
@ -796,8 +794,7 @@ class StickersManager final : public Actor {
StickerFormat sticker_format, StickerType sticker_type,
bool for_thumbnail);
Result<std::tuple<FileId, bool, bool>> prepare_input_sticker(td_api::inputSticker *sticker,
StickerFormat sticker_format, StickerType sticker_type);
Result<std::tuple<FileId, bool, bool>> prepare_input_sticker(td_api::inputSticker *sticker, StickerType sticker_type);
tl_object_ptr<telegram_api::inputStickerSetItem> get_input_sticker(const td_api::inputSticker *sticker,
FileId file_id) const;
@ -820,7 +817,8 @@ class StickersManager final : public Actor {
void on_sticker_set_thumbnail_uploaded(int64 random_id, Result<Unit> result);
void do_set_sticker_set_thumbnail(UserId user_id, string short_name, tl_object_ptr<td_api::InputFile> &&thumbnail,
void do_set_sticker_set_thumbnail(UserId user_id, string short_name,
td_api::object_ptr<td_api::InputFile> &&thumbnail, StickerFormat format,
Promise<Unit> &&promise);
void do_set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,

View File

@ -8202,10 +8202,10 @@ void Td::on_request(uint64 id, td_api::createNewStickerSet &request) {
CLEAN_INPUT_STRING(request.name_);
CLEAN_INPUT_STRING(request.source_);
CREATE_REQUEST_PROMISE();
stickers_manager_->create_new_sticker_set(
UserId(request.user_id_), std::move(request.title_), std::move(request.name_),
get_sticker_format(request.sticker_format_), get_sticker_type(request.sticker_type_), request.needs_repainting_,
std::move(request.stickers_), std::move(request.source_), std::move(promise));
stickers_manager_->create_new_sticker_set(UserId(request.user_id_), std::move(request.title_),
std::move(request.name_), get_sticker_type(request.sticker_type_),
request.needs_repainting_, std::move(request.stickers_),
std::move(request.source_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::addStickerToSet &request) {
@ -8221,7 +8221,8 @@ void Td::on_request(uint64 id, td_api::setStickerSetThumbnail &request) {
CLEAN_INPUT_STRING(request.name_);
CREATE_OK_REQUEST_PROMISE();
stickers_manager_->set_sticker_set_thumbnail(UserId(request.user_id_), std::move(request.name_),
std::move(request.thumbnail_), std::move(promise));
std::move(request.thumbnail_), get_sticker_format(request.format_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setCustomEmojiStickerSetThumbnail &request) {

View File

@ -3516,11 +3516,11 @@ class CliClient final : public Actor {
get_args(args, title, name, stickers);
auto input_stickers =
transform(autosplit(stickers), [op](Slice sticker) -> td_api::object_ptr<td_api::inputSticker> {
return td_api::make_object<td_api::inputSticker>(as_input_file(sticker), "😀", as_mask_position(op),
vector<string>{"keyword"});
return td_api::make_object<td_api::inputSticker>(as_input_file(sticker), as_sticker_format(op), "😀",
as_mask_position(op), vector<string>{"keyword"});
});
send_request(td_api::make_object<td_api::createNewStickerSet>(
my_id_, title, name, as_sticker_format(op), as_sticker_type(op), false, std::move(input_stickers), "tg_cli"));
send_request(td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, as_sticker_type(op), 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") {