Simplify StickersManager::upload_sticker_file.

This commit is contained in:
levlam 2023-02-14 16:10:27 +03:00
parent 7be16c8a68
commit e8d022e52c
3 changed files with 11 additions and 13 deletions

View File

@ -8048,8 +8048,8 @@ Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_file(
return std::make_tuple(file_id, is_url, is_local); 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, FileId StickersManager::upload_sticker_file(UserId user_id, StickerFormat sticker_format,
td_api::object_ptr<td_api::InputFile> &&input_file, const td_api::object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) { 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) {
@ -8062,13 +8062,13 @@ FileId StickersManager::upload_sticker_file(UserId user_id, td_api::object_ptr<t
return FileId(); return FileId();
} }
if (sticker_format == nullptr) { if (sticker_format == StickerFormat::Unknown) {
promise.set_error(Status::Error(400, "Sticker format must be non-empty")); promise.set_error(Status::Error(400, "Sticker format must be non-empty"));
return FileId(); return FileId();
} }
// StickerType::Regular has less restrictions // StickerType::Regular has less restrictions
auto r_file_id = prepare_input_file(input_file, get_sticker_format(sticker_format), StickerType::Regular, false); auto r_file_id = prepare_input_file(input_file, sticker_format, StickerType::Regular, false);
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();

View File

@ -287,8 +287,8 @@ class StickersManager final : public Actor {
void move_sticker_set_to_top_by_custom_emoji_ids(const vector<CustomEmojiId> &custom_emoji_ids); void move_sticker_set_to_top_by_custom_emoji_ids(const vector<CustomEmojiId> &custom_emoji_ids);
FileId upload_sticker_file(UserId user_id, td_api::object_ptr<td_api::StickerFormat> &&sticker_format, FileId upload_sticker_file(UserId user_id, StickerFormat sticker_format,
td_api::object_ptr<td_api::InputFile> &&input_file, Promise<Unit> &&promise); const td_api::object_ptr<td_api::InputFile> &input_file, Promise<Unit> &&promise);
void get_suggested_sticker_set_name(string title, Promise<string> &&promise); void get_suggested_sticker_set_name(string title, Promise<string> &&promise);

View File

@ -2194,14 +2194,13 @@ class ChangeStickerSetRequest final : public RequestOnceActor {
class UploadStickerFileRequest final : public RequestOnceActor { class UploadStickerFileRequest final : public RequestOnceActor {
UserId user_id_; UserId user_id_;
td_api::object_ptr<td_api::StickerFormat> sticker_format_; StickerFormat sticker_format_;
td_api::object_ptr<td_api::InputFile> input_file_; td_api::object_ptr<td_api::InputFile> input_file_;
FileId file_id; FileId file_id;
void do_run(Promise<Unit> &&promise) final { void do_run(Promise<Unit> &&promise) final {
file_id = td_->stickers_manager_->upload_sticker_file(user_id_, std::move(sticker_format_), std::move(input_file_), file_id = td_->stickers_manager_->upload_sticker_file(user_id_, sticker_format_, input_file_, std::move(promise));
std::move(promise));
} }
void do_send_result() final { void do_send_result() final {
@ -2209,12 +2208,11 @@ class UploadStickerFileRequest final : public RequestOnceActor {
} }
public: public:
UploadStickerFileRequest(ActorShared<Td> td, uint64 request_id, int64 user_id, UploadStickerFileRequest(ActorShared<Td> td, uint64 request_id, int64 user_id, StickerFormat sticker_format,
td_api::object_ptr<td_api::StickerFormat> sticker_format_,
td_api::object_ptr<td_api::InputFile> input_file) td_api::object_ptr<td_api::InputFile> input_file)
: RequestOnceActor(std::move(td), request_id) : RequestOnceActor(std::move(td), request_id)
, user_id_(user_id) , user_id_(user_id)
, sticker_format_(std::move(sticker_format_)) , sticker_format_(sticker_format)
, input_file_(std::move(input_file)) { , input_file_(std::move(input_file)) {
} }
}; };
@ -7252,7 +7250,7 @@ void Td::on_request(uint64 id, td_api::reorderInstalledStickerSets &request) {
} }
void Td::on_request(uint64 id, td_api::uploadStickerFile &request) { void Td::on_request(uint64 id, td_api::uploadStickerFile &request) {
CREATE_REQUEST(UploadStickerFileRequest, request.user_id_, std::move(request.sticker_format_), CREATE_REQUEST(UploadStickerFileRequest, request.user_id_, get_sticker_format(request.sticker_format_),
std::move(request.sticker_)); std::move(request.sticker_));
} }