Move out StickerType from inputSticker.

This commit is contained in:
levlam 2022-07-21 17:31:27 +03:00
parent 342bf8c41f
commit b5468e4cac
5 changed files with 32 additions and 30 deletions

View File

@ -4023,9 +4023,8 @@ proxies proxies:vector<proxy> = Proxies;
//@sticker File with the sticker; must fit in a 512x512 square. For WEBP stickers and masks the file must be in PNG format, which will be converted to WEBP server-side. Otherwise, the file must be local or uploaded within a week. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements //@sticker File with the sticker; must fit in a 512x512 square. For WEBP stickers and masks the file must be in PNG format, which will be converted to WEBP server-side. Otherwise, the file must be local or uploaded within a week. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
//@emojis Emojis corresponding to the sticker //@emojis Emojis corresponding to the sticker
//@format Sticker format //@format Sticker format
//@type Sticker type
//@mask_position Position where the mask is placed; pass null if not specified //@mask_position Position where the mask is placed; pass null if not specified
inputSticker sticker:InputFile emojis:string format:StickerFormat type:StickerType mask_position:maskPosition = InputSticker; inputSticker sticker:InputFile emojis:string format:StickerFormat mask_position:maskPosition = 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 //@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
@ -6412,9 +6411,10 @@ checkStickerSetName name:string = CheckStickerSetNameResult;
//@user_id Sticker set owner; ignored for regular users //@user_id Sticker set owner; ignored for regular users
//@title Sticker set title; 1-64 characters //@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 //@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_type Type of the stickers in the set
//@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 //@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 //@source Source of the sticker set; may be empty if unknown
createNewStickerSet user_id:int53 title:string name:string stickers:vector<inputSticker> source:string = StickerSet; createNewStickerSet user_id:int53 title:string name:string sticker_type:StickerType stickers:vector<inputSticker> source:string = StickerSet;
//@description Adds a new sticker to a set; for bots only. Returns the sticker set //@description Adds a new sticker to a set; for bots only. Returns the sticker set
//@user_id Sticker set owner @name Sticker set name @sticker Sticker to add to the set //@user_id Sticker set owner @name Sticker set name @sticker Sticker to add to the set

View File

@ -6095,7 +6095,7 @@ void StickersManager::reorder_installed_sticker_sets(StickerType sticker_type,
} }
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_sticker( Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_sticker(
td_api::inputSticker *sticker) { td_api::inputSticker *sticker, StickerType sticker_type) {
if (sticker == nullptr) { if (sticker == nullptr) {
return Status::Error(400, "Input sticker must be non-empty"); return Status::Error(400, "Input sticker must be non-empty");
} }
@ -6108,8 +6108,7 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
return Status::Error(400, "Sticker format must be non-empty"); return Status::Error(400, "Sticker format must be non-empty");
} }
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), sticker_type, false);
::td::get_sticker_type(sticker->type_), false);
} }
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file( Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file(
@ -6173,7 +6172,8 @@ FileId StickersManager::upload_sticker_file(UserId user_id, tl_object_ptr<td_api
return FileId(); return FileId();
} }
auto r_file_id = prepare_input_sticker(sticker.get()); // StickerType::Regular has less restrictions
auto r_file_id = prepare_input_sticker(sticker.get(), StickerType::Regular);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
promise.set_error(r_file_id.move_as_error()); promise.set_error(r_file_id.move_as_error());
return FileId(); return FileId();
@ -6279,8 +6279,9 @@ td_api::object_ptr<td_api::CheckStickerSetNameResult> StickersManager::get_check
} }
void StickersManager::create_new_sticker_set(UserId user_id, string &title, string &short_name, void StickersManager::create_new_sticker_set(UserId user_id, string &title, string &short_name,
vector<tl_object_ptr<td_api::inputSticker>> &&stickers, string software, StickerType sticker_type,
Promise<Unit> &&promise) { vector<td_api::object_ptr<td_api::inputSticker>> &&stickers,
string software, Promise<Unit> &&promise) {
bool is_bot = td_->auth_manager_->is_bot(); bool is_bot = td_->auth_manager_->is_bot();
if (!is_bot) { if (!is_bot) {
user_id = td_->contacts_manager_->get_my_id(); user_id = td_->contacts_manager_->get_my_id();
@ -6307,10 +6308,9 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
vector<FileId> local_file_ids; vector<FileId> local_file_ids;
vector<FileId> url_file_ids; vector<FileId> url_file_ids;
FlatHashSet<int32> sticker_formats; FlatHashSet<int32> sticker_formats;
FlatHashSet<int32> sticker_types;
StickerFormat sticker_format = StickerFormat::Unknown; StickerFormat sticker_format = StickerFormat::Unknown;
for (auto &sticker : stickers) { for (auto &sticker : stickers) {
auto r_file_id = prepare_input_sticker(sticker.get()); auto r_file_id = prepare_input_sticker(sticker.get(), sticker_type);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error()); return promise.set_error(r_file_id.move_as_error());
} }
@ -6322,7 +6322,6 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
return promise.set_error(Status::Error(400, "Animated stickers can't be uploaded by 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); sticker_formats.insert(static_cast<int32>(get_sticker_format(sticker->format_)) + 1);
sticker_types.insert(static_cast<int32>(::td::get_sticker_type(sticker->type_)) + 1);
file_ids.push_back(file_id); file_ids.push_back(file_id);
if (is_url) { if (is_url) {
@ -6334,15 +6333,13 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
if (sticker_formats.size() != 1) { if (sticker_formats.size() != 1) {
return promise.set_error(Status::Error(400, "All stickers must be of the same format")); return promise.set_error(Status::Error(400, "All stickers must be of the same format"));
} }
if (sticker_types.size() != 1) {
return promise.set_error(Status::Error(400, "All stickers must be of the same type"));
}
auto pending_new_sticker_set = make_unique<PendingNewStickerSet>(); auto pending_new_sticker_set = make_unique<PendingNewStickerSet>();
pending_new_sticker_set->user_id = user_id; pending_new_sticker_set->user_id = user_id;
pending_new_sticker_set->title = std::move(title); pending_new_sticker_set->title = std::move(title);
pending_new_sticker_set->short_name = short_name; pending_new_sticker_set->short_name = short_name;
pending_new_sticker_set->sticker_format = sticker_format; pending_new_sticker_set->sticker_format = sticker_format;
pending_new_sticker_set->sticker_type = sticker_type;
pending_new_sticker_set->file_ids = std::move(file_ids); pending_new_sticker_set->file_ids = std::move(file_ids);
pending_new_sticker_set->stickers = std::move(stickers); pending_new_sticker_set->stickers = std::move(stickers);
pending_new_sticker_set->software = std::move(software); pending_new_sticker_set->software = std::move(software);
@ -6510,8 +6507,8 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> res
auto &promise = pending_new_sticker_set->promise; auto &promise = pending_new_sticker_set->promise;
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id)); TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id));
StickerType sticker_type = ::td::get_sticker_type(pending_new_sticker_set->stickers[0]->type_);
StickerFormat sticker_format = pending_new_sticker_set->sticker_format; StickerFormat sticker_format = pending_new_sticker_set->sticker_format;
StickerType sticker_type = pending_new_sticker_set->sticker_type;
auto sticker_count = pending_new_sticker_set->stickers.size(); auto sticker_count = pending_new_sticker_set->stickers.size();
vector<tl_object_ptr<telegram_api::inputStickerSetItem>> input_stickers; vector<tl_object_ptr<telegram_api::inputStickerSetItem>> input_stickers;
@ -6564,7 +6561,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")); return promise.set_error(Status::Error(400, "Sticker set not found"));
} }
auto r_file_id = prepare_input_sticker(sticker.get()); auto r_file_id = prepare_input_sticker(sticker.get(), sticker_set->sticker_type);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error()); return promise.set_error(r_file_id.move_as_error());
} }

View File

@ -230,8 +230,8 @@ class StickersManager final : public Actor {
static td_api::object_ptr<td_api::CheckStickerSetNameResult> get_check_sticker_set_name_result_object( static td_api::object_ptr<td_api::CheckStickerSetNameResult> get_check_sticker_set_name_result_object(
CheckStickerSetNameResult result); CheckStickerSetNameResult result);
void create_new_sticker_set(UserId user_id, string &title, string &short_name, void create_new_sticker_set(UserId user_id, string &title, string &short_name, StickerType sticker_type,
vector<tl_object_ptr<td_api::inputSticker>> &&stickers, string software, vector<td_api::object_ptr<td_api::inputSticker>> &&stickers, string software,
Promise<Unit> &&promise); Promise<Unit> &&promise);
void add_sticker_to_set(UserId user_id, string &short_name, tl_object_ptr<td_api::inputSticker> &&sticker, void add_sticker_to_set(UserId user_id, string &short_name, tl_object_ptr<td_api::inputSticker> &&sticker,
@ -425,6 +425,7 @@ class StickersManager final : public Actor {
UserId user_id; UserId user_id;
string title; string title;
string short_name; string short_name;
StickerType sticker_type = StickerType::Regular;
StickerFormat sticker_format = StickerFormat::Unknown; StickerFormat sticker_format = StickerFormat::Unknown;
vector<FileId> file_ids; vector<FileId> file_ids;
vector<tl_object_ptr<td_api::inputSticker>> stickers; vector<tl_object_ptr<td_api::inputSticker>> stickers;
@ -674,7 +675,8 @@ class StickersManager final : public Actor {
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_file( 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); const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, StickerType type, bool for_thumbnail);
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_sticker(td_api::inputSticker *sticker); Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_sticker(td_api::inputSticker *sticker,
StickerType sticker_type);
tl_object_ptr<telegram_api::inputStickerSetItem> get_input_sticker(const td_api::inputSticker *sticker, tl_object_ptr<telegram_api::inputStickerSetItem> get_input_sticker(const td_api::inputSticker *sticker,
FileId file_id) const; FileId file_id) const;

View File

@ -2236,12 +2236,13 @@ class CreateNewStickerSetRequest final : public RequestOnceActor {
UserId user_id_; UserId user_id_;
string title_; string title_;
string name_; string name_;
vector<tl_object_ptr<td_api::inputSticker>> stickers_; StickerType sticker_type_;
vector<td_api::object_ptr<td_api::inputSticker>> stickers_;
string software_; string software_;
void do_run(Promise<Unit> &&promise) final { void do_run(Promise<Unit> &&promise) final {
td_->stickers_manager_->create_new_sticker_set(user_id_, title_, name_, std::move(stickers_), std::move(software_), td_->stickers_manager_->create_new_sticker_set(user_id_, title_, name_, sticker_type_, std::move(stickers_),
std::move(promise)); std::move(software_), std::move(promise));
} }
void do_send_result() final { void do_send_result() final {
@ -2254,11 +2255,13 @@ class CreateNewStickerSetRequest final : public RequestOnceActor {
public: public:
CreateNewStickerSetRequest(ActorShared<Td> td, uint64 request_id, int64 user_id, string &&title, string &&name, CreateNewStickerSetRequest(ActorShared<Td> td, uint64 request_id, int64 user_id, string &&title, string &&name,
vector<tl_object_ptr<td_api::inputSticker>> &&stickers, string &&software) StickerType sticker_type, vector<td_api::object_ptr<td_api::inputSticker>> &&stickers,
string &&software)
: RequestOnceActor(std::move(td), request_id) : RequestOnceActor(std::move(td), request_id)
, user_id_(user_id) , user_id_(user_id)
, title_(std::move(title)) , title_(std::move(title))
, name_(std::move(name)) , name_(std::move(name))
, sticker_type_(sticker_type)
, stickers_(std::move(stickers)) , stickers_(std::move(stickers))
, software_(std::move(software)) { , software_(std::move(software)) {
} }
@ -7090,7 +7093,7 @@ void Td::on_request(uint64 id, td_api::createNewStickerSet &request) {
CLEAN_INPUT_STRING(request.name_); CLEAN_INPUT_STRING(request.name_);
CLEAN_INPUT_STRING(request.source_); CLEAN_INPUT_STRING(request.source_);
CREATE_REQUEST(CreateNewStickerSetRequest, request.user_id_, std::move(request.title_), std::move(request.name_), CREATE_REQUEST(CreateNewStickerSetRequest, request.user_id_, std::move(request.title_), std::move(request.name_),
std::move(request.stickers_), std::move(request.source_)); get_sticker_type(request.sticker_type_), std::move(request.stickers_), std::move(request.source_));
} }
void Td::on_request(uint64 id, td_api::addStickerToSet &request) { void Td::on_request(uint64 id, td_api::addStickerToSet &request) {

View File

@ -2724,10 +2724,10 @@ class CliClient final : public Actor {
} else if (op == "cssn") { } else if (op == "cssn") {
const string &name = args; const string &name = args;
send_request(td_api::make_object<td_api::checkStickerSetName>(name)); send_request(td_api::make_object<td_api::checkStickerSetName>(name));
} else if (op == "usf" || op == "usfa" || op == "usfv" || op == "usfm" || op == "usfe") { } else if (op == "usf" || op == "usfa" || op == "usfv") {
send_request(td_api::make_object<td_api::uploadStickerFile>( send_request(td_api::make_object<td_api::uploadStickerFile>(
-1, td_api::make_object<td_api::inputSticker>(as_input_file(args), "😀", as_sticker_format(op), -1, td_api::make_object<td_api::inputSticker>(as_input_file(args), "😀", as_sticker_format(op),
as_sticker_type(op), as_mask_position(op)))); as_mask_position(op))));
} else if (op == "cnss" || op == "cnssa" || op == "cnssv" || op == "cnssm" || op == "cnsse") { } else if (op == "cnss" || op == "cnssa" || op == "cnssv" || op == "cnssm" || op == "cnsse") {
string title; string title;
string name; string name;
@ -2736,10 +2736,10 @@ class CliClient final : public Actor {
auto input_stickers = auto input_stickers =
transform(autosplit(stickers), [op](Slice sticker) -> td_api::object_ptr<td_api::inputSticker> { 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), return td_api::make_object<td_api::inputSticker>(as_input_file(sticker), "😀", as_sticker_format(op),
as_sticker_type(op), as_mask_position(op)); as_mask_position(op));
}); });
send_request( send_request(td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, as_sticker_type(op),
td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, std::move(input_stickers), "tg_cli")); std::move(input_stickers), "tg_cli"));
} else if (op == "sss") { } else if (op == "sss") {
send_request(td_api::make_object<td_api::searchStickerSet>(args)); send_request(td_api::make_object<td_api::searchStickerSet>(args));
} else if (op == "siss") { } else if (op == "siss") {