Add td_api::setCustomEmojiStickerSetThumbnail.

This commit is contained in:
levlam 2023-02-08 21:29:54 +03:00
parent 5bbac9d0b4
commit 9871aba024
5 changed files with 100 additions and 0 deletions

View File

@ -7999,6 +7999,11 @@ addStickerToSet user_id:int53 name:string sticker:inputSticker = StickerSet;
//@thumbnail Thumbnail to set in PNG, TGS, or WEBM format; pass null to remove the sticker set thumbnail. Thumbnail format must match the format of stickers in the set
setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile = StickerSet;
//@description Sets a custom emoji sticker set thumbnail; for bots only
//@name Sticker set name
//@custom_emoji_id Identifier of the custom emoji from the sticker set, which will be set as sticker set thumbnail; pass 0 to remove the sticker set thumbnail
setCustomEmojiStickerSetThumbnail name:string custom_emoji_id:int64 = Ok;
//@description Changes the position of a sticker in the set to which it belongs; for bots only. The sticker set must have been created by the bot
//@sticker Sticker
//@position New position of the sticker in the set, 0-based

View File

@ -1254,6 +1254,40 @@ class SetStickerSetThumbnailQuery final : public Td::ResultHandler {
}
};
class SetCustomEmojiStickerSetThumbnailQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SetCustomEmojiStickerSetThumbnailQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &short_name, CustomEmojiId custom_emoji_id) {
int32 flags = telegram_api::stickers_setStickerSetThumb::THUMB_DOCUMENT_ID_MASK;
send_query(G()->net_query_creator().create(
telegram_api::stickers_setStickerSetThumb(
flags, make_tl_object<telegram_api::inputStickerSetShortName>(short_name), nullptr, custom_emoji_id.get()),
{{short_name}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stickers_setStickerSetThumb>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
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(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class SetStickerPositionQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -8390,6 +8424,10 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_
if (sticker_set == nullptr || !sticker_set->was_loaded_) {
return promise.set_error(Status::Error(400, "Sticker set not found"));
}
if (sticker_set->sticker_type_ == StickerType::CustomEmoji) {
return promise.set_error(
Status::Error(400, "The method can't be used to set thumbnail of custom emoji sticker sets"));
}
auto r_file_id = prepare_input_file(thumbnail, sticker_set->sticker_format_, sticker_set->sticker_type_, true);
if (r_file_id.is_error()) {
@ -8453,6 +8491,47 @@ void StickersManager::on_sticker_set_thumbnail_uploaded(int64 random_id, Result<
->send(pending_set_sticker_set_thumbnail->short_name_, file_view.main_remote_location().as_input_document());
}
void StickersManager::set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise) {
short_name = clean_username(strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH));
if (short_name.empty()) {
return promise.set_error(Status::Error(400, "Sticker set name must be non-empty"));
}
const StickerSet *sticker_set = get_sticker_set(short_name_to_sticker_set_id_.get(short_name));
if (sticker_set != nullptr && sticker_set->was_loaded_) {
return do_set_custom_emoji_sticker_set_thumbnail(short_name, custom_emoji_id, std::move(promise));
}
do_reload_sticker_set(StickerSetId(), make_tl_object<telegram_api::inputStickerSetShortName>(short_name), 0,
PromiseCreator::lambda([actor_id = actor_id(this), short_name, custom_emoji_id,
promise = std::move(promise)](Result<Unit> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &StickersManager::do_set_custom_emoji_sticker_set_thumbnail,
std::move(short_name), custom_emoji_id, std::move(promise));
}
}),
"set_custom_emoji_sticker_set_thumbnail");
}
void StickersManager::do_set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
const StickerSet *sticker_set = get_sticker_set(short_name_to_sticker_set_id_.get(short_name));
if (sticker_set == nullptr || !sticker_set->was_loaded_) {
return promise.set_error(Status::Error(400, "Sticker set not found"));
}
if (sticker_set->sticker_type_ != StickerType::CustomEmoji) {
return promise.set_error(
Status::Error(400, "The method can be used to set thumbnail only for custom emoji sticker sets"));
}
td_->create_handler<SetCustomEmojiStickerSetThumbnailQuery>(std::move(promise))->send(short_name, custom_emoji_id);
}
Result<StickersManager::StickerInputDocument> StickersManager::get_sticker_input_document(
const tl_object_ptr<td_api::InputFile> &sticker) const {
TRY_RESULT(file_id, td_->file_manager_->get_input_file_id(FileType::Sticker, sticker, DialogId(), false, false));

View File

@ -305,6 +305,9 @@ class StickersManager final : public Actor {
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_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise);
void set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise);
@ -859,6 +862,9 @@ class StickersManager final : public Actor {
void do_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 do_set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise);
struct StickerInputDocument {
string sticker_set_short_name_;
telegram_api::object_ptr<telegram_api::inputDocument> input_document_;

View File

@ -7303,6 +7303,14 @@ void Td::on_request(uint64 id, td_api::setStickerSetThumbnail &request) {
std::move(request.thumbnail_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setCustomEmojiStickerSetThumbnail &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.name_);
CREATE_OK_REQUEST_PROMISE();
stickers_manager_->set_custom_emoji_sticker_set_thumbnail(
std::move(request.name_), CustomEmojiId(request.custom_emoji_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setStickerPositionInSet &request) {
CHECK_IS_BOT();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1200,6 +1200,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setStickerSetThumbnail &request);
void on_request(uint64 id, td_api::setCustomEmojiStickerSetThumbnail &request);
void on_request(uint64 id, td_api::setStickerPositionInSet &request);
void on_request(uint64 id, td_api::removeStickerFromSet &request);