Use request promise in addStickerToSet.

This commit is contained in:
levlam 2022-08-08 17:01:04 +03:00
parent 74c03d35a7
commit 57de8b5b09
3 changed files with 20 additions and 40 deletions

View File

@ -1080,10 +1080,11 @@ class CreateNewStickerSetQuery final : public Td::ResultHandler {
};
class AddStickerToSetQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
Promise<td_api::object_ptr<td_api::stickerSet>> promise_;
public:
explicit AddStickerToSetQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
explicit AddStickerToSetQuery(Promise<td_api::object_ptr<td_api::stickerSet>> &&promise)
: promise_(std::move(promise)) {
}
void send(const string &short_name, tl_object_ptr<telegram_api::inputStickerSetItem> &&input_sticker) {
@ -1099,10 +1100,10 @@ class AddStickerToSetQuery 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,
"AddStickerToSetQuery");
auto sticker_set_id = td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), result_ptr.move_as_ok(),
true, "AddStickerToSetQuery");
promise_.set_value(Unit());
promise_.set_value(td_->stickers_manager_->get_sticker_set_object(sticker_set_id));
}
void on_error(Status status) final {
@ -7108,8 +7109,9 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> res
sticker_format, std::move(input_stickers), pending_new_sticker_set->software_);
}
void StickersManager::add_sticker_to_set(UserId user_id, string &short_name,
tl_object_ptr<td_api::inputSticker> &&sticker, Promise<Unit> &&promise) {
void StickersManager::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) {
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));
@ -7136,7 +7138,8 @@ void StickersManager::add_sticker_to_set(UserId user_id, string &short_name,
}
void StickersManager::do_add_sticker_to_set(UserId user_id, string short_name,
tl_object_ptr<td_api::inputSticker> &&sticker, Promise<Unit> &&promise) {
tl_object_ptr<td_api::inputSticker> &&sticker,
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));
@ -7186,6 +7189,8 @@ void StickersManager::on_added_sticker_uploaded(int64 random_id, Result<Unit> re
pending_add_sticker_to_sets_.erase(it);
TRY_STATUS_PROMISE(pending_add_sticker_to_set->promise_, G()->close_status());
if (result.is_error()) {
pending_add_sticker_to_set->promise_.set_error(result.move_as_error());
return;

View File

@ -247,8 +247,8 @@ class StickersManager final : public Actor {
vector<td_api::object_ptr<td_api::inputSticker>> &&stickers, string software,
Promise<Unit> &&promise);
void add_sticker_to_set(UserId user_id, string &short_name, tl_object_ptr<td_api::inputSticker> &&sticker,
Promise<Unit> &&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);
void set_sticker_set_thumbnail(UserId user_id, string &short_name, tl_object_ptr<td_api::InputFile> &&thumbnail,
Promise<Unit> &&promise);
@ -455,7 +455,7 @@ class StickersManager final : public Actor {
string short_name_;
FileId file_id_;
tl_object_ptr<td_api::inputSticker> sticker_;
Promise<> promise_;
Promise<td_api::object_ptr<td_api::stickerSet>> promise_;
};
struct PendingSetStickerSetThumbnail {
@ -744,7 +744,7 @@ class StickersManager final : public Actor {
void on_added_sticker_uploaded(int64 random_id, Result<Unit> result);
void do_add_sticker_to_set(UserId user_id, string short_name, tl_object_ptr<td_api::inputSticker> &&sticker,
Promise<Unit> &&promise);
Promise<td_api::object_ptr<td_api::stickerSet>> &&promise);
void on_sticker_set_thumbnail_uploaded(int64 random_id, Result<Unit> result);

View File

@ -2255,33 +2255,6 @@ class CreateNewStickerSetRequest final : public RequestOnceActor {
}
};
class AddStickerToSetRequest final : public RequestOnceActor {
UserId user_id_;
string name_;
tl_object_ptr<td_api::inputSticker> sticker_;
void do_run(Promise<Unit> &&promise) final {
td_->stickers_manager_->add_sticker_to_set(user_id_, name_, std::move(sticker_), 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:
AddStickerToSetRequest(ActorShared<Td> td, uint64 request_id, int64 user_id, string &&name,
tl_object_ptr<td_api::inputSticker> &&sticker)
: RequestOnceActor(std::move(td), request_id)
, user_id_(user_id)
, name_(std::move(name))
, sticker_(std::move(sticker)) {
}
};
class SetStickerSetThumbnailRequest final : public RequestOnceActor {
UserId user_id_;
string name_;
@ -7095,7 +7068,9 @@ void Td::on_request(uint64 id, td_api::createNewStickerSet &request) {
void Td::on_request(uint64 id, td_api::addStickerToSet &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.name_);
CREATE_REQUEST(AddStickerToSetRequest, request.user_id_, std::move(request.name_), std::move(request.sticker_));
CREATE_REQUEST_PROMISE();
stickers_manager_->add_sticker_to_set(UserId(request.user_id_), std::move(request.name_), std::move(request.sticker_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setStickerSetThumbnail &request) {