Move sticker_format out of inputSticker.

This commit is contained in:
levlam 2023-02-14 14:59:03 +03:00
parent ae0a473cb9
commit 7be16c8a68
6 changed files with 46 additions and 45 deletions

View File

@ -5026,10 +5026,9 @@ proxies proxies:vector<proxy> = Proxies;
//@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
//@emojis String with 1-20 emoji corresponding to the sticker
//@format Sticker format
//@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 format:StickerFormat mask_position:maskPosition keywords:vector<string> = InputSticker;
inputSticker sticker:InputFile 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
@ -7986,11 +7985,13 @@ 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 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_type:StickerType needs_repainting:Bool stickers:vector<inputSticker> source:string = StickerSet;
createNewStickerSet user_id:int53 title:string name:string sticker_format:StickerFormat sticker_type:StickerType needs_repainting:Bool stickers:vector<inputSticker> source:string = StickerSet;
//@description Adds a new sticker to a set; for bots only. Returns the sticker set
//@user_id Sticker set owner

View File

@ -11,7 +11,9 @@
namespace td {
StickerFormat get_sticker_format(const td_api::object_ptr<td_api::StickerFormat> &format) {
CHECK(format != nullptr);
if (format == nullptr) {
return StickerFormat::Unknown;
}
switch (format->get_id()) {
case td_api::stickerFormatWebp::ID:
return StickerFormat::Webp;

View File

@ -7978,8 +7978,9 @@ void StickersManager::move_sticker_set_to_top_by_custom_emoji_ids(const vector<C
}
}
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_sticker(
td_api::inputSticker *sticker, StickerType sticker_type) {
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");
}
@ -7999,26 +8000,23 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
}
}
if (sticker->format_ == nullptr) {
return Status::Error(400, "Sticker format must be non-empty");
}
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), sticker_type, false);
return prepare_input_file(sticker->sticker_, sticker_format, sticker_type, false);
}
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file(
const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, StickerType type, bool for_thumbnail) {
auto file_type = format == StickerFormat::Tgs ? FileType::Sticker : FileType::Document;
Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_file(
const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat sticker_format, StickerType sticker_type,
bool for_thumbnail) {
auto file_type = sticker_format == StickerFormat::Tgs ? FileType::Sticker : FileType::Document;
TRY_RESULT(file_id, td_->file_manager_->get_input_file_id(file_type, input_file, DialogId(), for_thumbnail, false));
if (file_id.empty()) {
return std::make_tuple(FileId(), false, false, StickerFormat::Unknown);
return std::make_tuple(FileId(), false, false);
}
if (format == StickerFormat::Tgs) {
if (sticker_format == StickerFormat::Tgs) {
int32 width = for_thumbnail ? 100 : 512;
create_sticker(file_id, FileId(), string(), PhotoSize(), get_dimensions(width, width, "prepare_input_file"),
nullptr, nullptr, format, nullptr);
} else if (format == StickerFormat::Webm) {
nullptr, nullptr, sticker_format, nullptr);
} else if (sticker_format == StickerFormat::Webm) {
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.webm", "video/webm", false);
} else {
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.png", "image/png", false);
@ -8041,13 +8039,13 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
is_url = true;
} else {
if (file_view.has_local_location() &&
file_view.expected_size() > get_max_sticker_file_size(format, type, for_thumbnail)) {
file_view.expected_size() > get_max_sticker_file_size(sticker_format, sticker_type, for_thumbnail)) {
return Status::Error(400, "File is too big");
}
is_local = true;
}
}
return std::make_tuple(file_id, is_url, is_local, format);
return std::make_tuple(file_id, is_url, is_local);
}
FileId StickersManager::upload_sticker_file(UserId user_id, td_api::object_ptr<td_api::StickerFormat> &&sticker_format,
@ -8160,7 +8158,8 @@ td_api::object_ptr<td_api::CheckStickerSetNameResult> StickersManager::get_check
}
}
void StickersManager::create_new_sticker_set(UserId user_id, string title, string short_name, StickerType sticker_type,
void StickersManager::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,
@ -8190,25 +8189,25 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin
return promise.set_error(Status::Error(400, "Only custom emoji stickers support repainting"));
}
if (sticker_format == StickerFormat::Unknown) {
return promise.set_error(Status::Error(400, "Sticker format must be non-empty"));
}
vector<FileId> file_ids;
file_ids.reserve(stickers.size());
vector<FileId> local_file_ids;
vector<FileId> url_file_ids;
FlatHashSet<int32> sticker_formats;
StickerFormat sticker_format = StickerFormat::Unknown;
for (auto &sticker : stickers) {
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_type);
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_format, sticker_type);
if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error());
}
auto file_id = std::get<0>(r_file_id.ok());
auto is_url = std::get<1>(r_file_id.ok());
auto is_local = std::get<2>(r_file_id.ok());
sticker_format = std::get<3>(r_file_id.ok());
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(static_cast<int32>(get_sticker_format(sticker->format_)) + 1);
file_ids.push_back(file_id);
if (is_url) {
@ -8217,9 +8216,6 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin
local_file_ids.push_back(file_id);
}
}
if (sticker_formats.size() != 1) {
return promise.set_error(Status::Error(400, "All stickers must be of the same format"));
}
auto pending_new_sticker_set = make_unique<PendingNewStickerSet>();
pending_new_sticker_set->user_id_ = user_id;
@ -8456,7 +8452,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(), sticker_set->sticker_type_);
auto r_file_id = prepare_input_sticker(sticker.get(), sticker_set->sticker_format_, sticker_set->sticker_type_);
if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error());
}

View File

@ -298,9 +298,10 @@ 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, 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, 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 add_sticker_to_set(UserId user_id, string short_name, tl_object_ptr<td_api::inputSticker> &&sticker,
Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
@ -846,11 +847,12 @@ class StickersManager final : public Actor {
std::pair<vector<FileId>, vector<FileId>> split_stickers_by_premium(const StickerSet *sticker_set) const;
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_file(
const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, StickerType type, bool for_thumbnail);
Result<std::tuple<FileId, bool, bool>> prepare_input_file(const tl_object_ptr<td_api::InputFile> &input_file,
StickerFormat sticker_format, StickerType sticker_type,
bool for_thumbnail);
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_sticker(td_api::inputSticker *sticker,
StickerType sticker_type);
Result<std::tuple<FileId, bool, bool>> prepare_input_sticker(td_api::inputSticker *sticker,
StickerFormat sticker_format, StickerType sticker_type);
tl_object_ptr<telegram_api::inputStickerSetItem> get_input_sticker(const td_api::inputSticker *sticker,
FileId file_id) const;

View File

@ -7288,10 +7288,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_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_format(request.sticker_format_), 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) {

View File

@ -2896,11 +2896,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_sticker_format(op),
as_mask_position(op), vector<string>{"keyword"});
return td_api::make_object<td_api::inputSticker>(as_input_file(sticker), "😀", as_mask_position(op),
vector<string>{"keyword"});
});
send_request(td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, 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_format(op), 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") {