Use request promise in setStickerSetThumbnail.
This commit is contained in:
parent
69b1cc7967
commit
594aa2ff6d
@ -1118,10 +1118,11 @@ class AddStickerToSetQuery final : public Td::ResultHandler {
|
||||
};
|
||||
|
||||
class SetStickerSetThumbnailQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> promise_;
|
||||
|
||||
public:
|
||||
explicit SetStickerSetThumbnailQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
explicit SetStickerSetThumbnailQuery(Promise<td_api::object_ptr<td_api::stickerSet>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &short_name, tl_object_ptr<telegram_api::InputDocument> &&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<Unit> 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<td_api::InputFile> &&thumbnail, Promise<Unit> &&promise) {
|
||||
void StickersManager::set_sticker_set_thumbnail(UserId user_id, string short_name,
|
||||
tl_object_ptr<td_api::InputFile> &&thumbnail,
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> &&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<td_api::InputFile> &&thumbnail,
|
||||
Promise<Unit> &&promise) {
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> &&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;
|
||||
|
@ -250,8 +250,8 @@ class StickersManager final : public Actor {
|
||||
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);
|
||||
|
||||
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, tl_object_ptr<td_api::InputFile> &&thumbnail,
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
|
||||
|
||||
void set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position,
|
||||
Promise<Unit> &&promise);
|
||||
@ -461,7 +461,7 @@ class StickersManager final : public Actor {
|
||||
struct PendingSetStickerSetThumbnail {
|
||||
string short_name_;
|
||||
FileId file_id_;
|
||||
Promise<> promise_;
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> promise_;
|
||||
};
|
||||
|
||||
struct PendingGetAnimatedEmojiClickSticker {
|
||||
@ -749,7 +749,7 @@ 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,
|
||||
Promise<Unit> &&promise);
|
||||
Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
|
||||
|
||||
bool update_sticker_set_cache(const StickerSet *sticker_set, Promise<Unit> &promise);
|
||||
|
||||
|
@ -2220,33 +2220,6 @@ class UploadStickerFileRequest final : public RequestOnceActor {
|
||||
}
|
||||
};
|
||||
|
||||
class SetStickerSetThumbnailRequest final : public RequestOnceActor {
|
||||
UserId user_id_;
|
||||
string name_;
|
||||
tl_object_ptr<td_api::InputFile> thumbnail_;
|
||||
|
||||
void do_run(Promise<Unit> &&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> td, uint64 request_id, int64 user_id, string &&name,
|
||||
tl_object_ptr<td_api::InputFile> &&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) {
|
||||
|
Loading…
Reference in New Issue
Block a user