Add td_api::setStickerSetTitle.

This commit is contained in:
levlam 2023-02-08 21:43:09 +03:00
parent 9871aba024
commit 8e2cbeebc1
5 changed files with 63 additions and 1 deletions

View File

@ -8004,6 +8004,9 @@ setStickerSetThumbnail user_id:int53 name:string thumbnail:InputFile = StickerSe
//@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 Sets a sticker set title; for bots only @name Sticker set name @title New sticker set title
setStickerSetTitle name:string title:string = 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

@ -1275,8 +1275,41 @@ class SetCustomEmojiStickerSetThumbnailQuery final : public Td::ResultHandler {
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, "SetCustomEmojiStickerSetThumbnailQuery");
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 SetStickerSetTitleQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SetStickerSetTitleQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &short_name, const string &title) {
send_query(
G()->net_query_creator().create(telegram_api::stickers_renameStickerSet(
make_tl_object<telegram_api::inputStickerSetShortName>(short_name), title),
{{short_name}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stickers_renameStickerSet>(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");
true, "SetStickerSetTitleQuery");
if (!sticker_set_id.is_valid()) {
return on_error(Status::Error(500, "Sticker set not found"));
}
@ -8532,6 +8565,20 @@ void StickersManager::do_set_custom_emoji_sticker_set_thumbnail(string short_nam
td_->create_handler<SetCustomEmojiStickerSetThumbnailQuery>(std::move(promise))->send(short_name, custom_emoji_id);
}
void StickersManager::set_sticker_set_title(string short_name, string title, 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"));
}
title = strip_empty_characters(title, MAX_STICKER_SET_TITLE_LENGTH);
if (title.empty()) {
return promise.set_error(Status::Error(400, "Sticker set title must be non-empty"));
}
td_->create_handler<SetStickerSetTitleQuery>(std::move(promise))->send(short_name, title);
}
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

@ -308,6 +308,8 @@ class StickersManager final : public Actor {
void set_custom_emoji_sticker_set_thumbnail(string short_name, CustomEmojiId custom_emoji_id,
Promise<Unit> &&promise);
void set_sticker_set_title(string short_name, string title, Promise<Unit> &&promise);
void set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise);

View File

@ -7311,6 +7311,14 @@ void Td::on_request(uint64 id, td_api::setCustomEmojiStickerSetThumbnail &reques
std::move(request.name_), CustomEmojiId(request.custom_emoji_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setStickerSetTitle &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.name_);
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();
stickers_manager_->set_sticker_set_title(std::move(request.name_), std::move(request.title_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setStickerPositionInSet &request) {
CHECK_IS_BOT();
CREATE_OK_REQUEST_PROMISE();

View File

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