diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index cb30bb297..c801a5ae7 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1118,10 +1118,11 @@ class AddStickerToSetQuery final : public Td::ResultHandler { }; class SetStickerSetThumbnailQuery final : public Td::ResultHandler { - Promise promise_; + Promise> promise_; public: - explicit SetStickerSetThumbnailQuery(Promise &&promise) : promise_(std::move(promise)) { + explicit SetStickerSetThumbnailQuery(Promise> &&promise) + : promise_(std::move(promise)) { } void send(const string &short_name, tl_object_ptr &&input_document) { @@ -1137,10 +1138,12 @@ class SetStickerSetThumbnailQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), result_ptr.move_as_ok(), true, - "SetStickerSetThumbnailQuery"); - - promise_.set_value(Unit()); + auto sticker_set_id = td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), result_ptr.move_as_ok(), + true, "SetStickerSetThumbnailQuery"); + if (!sticker_set_id.is_valid()) { + return on_error(Status::Error(500, "Sticker set not found")); + } + promise_.set_value(td_->stickers_manager_->get_sticker_set_object(sticker_set_id)); } void on_error(Status status) final { @@ -7207,8 +7210,9 @@ void StickersManager::on_added_sticker_uploaded(int64 random_id, Result re get_input_sticker(pending_add_sticker_to_set->sticker_.get(), pending_add_sticker_to_set->file_id_)); } -void StickersManager::set_sticker_set_thumbnail(UserId user_id, string &short_name, - tl_object_ptr &&thumbnail, Promise &&promise) { +void StickersManager::set_sticker_set_thumbnail(UserId user_id, string short_name, + tl_object_ptr &&thumbnail, + Promise> &&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)); @@ -7236,7 +7240,7 @@ void StickersManager::set_sticker_set_thumbnail(UserId user_id, string &short_na void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_name, tl_object_ptr &&thumbnail, - Promise &&promise) { + Promise> &&promise) { TRY_STATUS_PROMISE(promise, G()->close_status()); const StickerSet *sticker_set = get_sticker_set(short_name_to_sticker_set_id_.get(short_name)); @@ -7292,6 +7296,9 @@ void StickersManager::on_sticker_set_thumbnail_uploaded(int64 random_id, Result< pending_set_sticker_set_thumbnails_.erase(it); + if (G()->close_flag()) { + result = Global::request_aborted_error(); + } if (result.is_error()) { pending_set_sticker_set_thumbnail->promise_.set_error(result.move_as_error()); return; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index f8f085c2a..24891cfec 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -250,8 +250,8 @@ class StickersManager final : public Actor { void add_sticker_to_set(UserId user_id, string short_name, tl_object_ptr &&sticker, Promise> &&promise); - void set_sticker_set_thumbnail(UserId user_id, string &short_name, tl_object_ptr &&thumbnail, - Promise &&promise); + void set_sticker_set_thumbnail(UserId user_id, string short_name, tl_object_ptr &&thumbnail, + Promise> &&promise); void set_sticker_position_in_set(const tl_object_ptr &sticker, int32 position, Promise &&promise); @@ -461,7 +461,7 @@ class StickersManager final : public Actor { struct PendingSetStickerSetThumbnail { string short_name_; FileId file_id_; - Promise<> promise_; + Promise> promise_; }; struct PendingGetAnimatedEmojiClickSticker { @@ -749,7 +749,7 @@ class StickersManager final : public Actor { void on_sticker_set_thumbnail_uploaded(int64 random_id, Result result); void do_set_sticker_set_thumbnail(UserId user_id, string short_name, tl_object_ptr &&thumbnail, - Promise &&promise); + Promise> &&promise); bool update_sticker_set_cache(const StickerSet *sticker_set, Promise &promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index a6a9754b8..29f560ebf 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2220,33 +2220,6 @@ class UploadStickerFileRequest final : public RequestOnceActor { } }; -class SetStickerSetThumbnailRequest final : public RequestOnceActor { - UserId user_id_; - string name_; - tl_object_ptr thumbnail_; - - void do_run(Promise &&promise) final { - td_->stickers_manager_->set_sticker_set_thumbnail(user_id_, name_, std::move(thumbnail_), std::move(promise)); - } - - void do_send_result() final { - auto set_id = td_->stickers_manager_->search_sticker_set(name_, Auto()); - if (!set_id.is_valid()) { - return send_error(Status::Error(500, "Sticker set not found")); - } - send_result(td_->stickers_manager_->get_sticker_set_object(set_id)); - } - - public: - SetStickerSetThumbnailRequest(ActorShared td, uint64 request_id, int64 user_id, string &&name, - tl_object_ptr &&thumbnail) - : RequestOnceActor(std::move(td), request_id) - , user_id_(user_id) - , name_(std::move(name)) - , thumbnail_(std::move(thumbnail)) { - } -}; - class GetRecentStickersRequest final : public RequestActor<> { bool is_attached_; @@ -7044,8 +7017,9 @@ void Td::on_request(uint64 id, td_api::addStickerToSet &request) { void Td::on_request(uint64 id, td_api::setStickerSetThumbnail &request) { CHECK_IS_BOT(); CLEAN_INPUT_STRING(request.name_); - CREATE_REQUEST(SetStickerSetThumbnailRequest, request.user_id_, std::move(request.name_), - std::move(request.thumbnail_)); + CREATE_REQUEST_PROMISE(); + stickers_manager_->set_sticker_set_thumbnail(UserId(request.user_id_), std::move(request.name_), + std::move(request.thumbnail_), std::move(promise)); } void Td::on_request(uint64 id, td_api::setStickerPositionInSet &request) {