Add td_api::deleteStickerSet.

This commit is contained in:
levlam 2023-02-16 16:17:29 +03:00
parent c8c8b63e2b
commit 359ec5e66c
5 changed files with 63 additions and 2 deletions

View File

@ -8013,6 +8013,9 @@ 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 Deleted a sticker set; for bots only @name Sticker set name
deleteStickerSet name: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

@ -1321,6 +1321,38 @@ class SetStickerSetTitleQuery final : public Td::ResultHandler {
}
};
class DeleteStickerSetQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
string short_name_;
public:
explicit DeleteStickerSetQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &short_name) {
send_query(G()->net_query_creator().create(
telegram_api::stickers_deleteStickerSet(make_tl_object<telegram_api::inputStickerSetShortName>(short_name)),
{{short_name}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stickers_deleteStickerSet>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
if (!result_ptr.ok()) {
return on_error(Status::Error(500, "Failed to delete sticker set"));
}
td_->stickers_manager_->on_sticker_set_deleted(short_name_);
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_;
@ -4028,6 +4060,11 @@ void StickersManager::on_load_sticker_set_fail(StickerSetId sticker_set_id, cons
update_load_requests(get_sticker_set(sticker_set_id), true, error);
}
void StickersManager::on_sticker_set_deleted(const string &short_name) {
// clear short_name_to_sticker_set_id_ to allow next searchStickerSet request to succeed
short_name_to_sticker_set_id_.erase(clean_username(short_name));
}
void StickersManager::update_load_requests(StickerSet *sticker_set, bool with_stickers, const Status &status) {
if (sticker_set == nullptr) {
return;
@ -4047,8 +4084,7 @@ void StickersManager::update_load_requests(StickerSet *sticker_set, bool with_st
if (status.message() == "STICKERSET_INVALID") {
// the sticker set is likely to be deleted
// clear short_name_to_sticker_set_id_ to allow next searchStickerSet request to succeed
short_name_to_sticker_set_id_.erase(clean_username(sticker_set->short_name_));
on_sticker_set_deleted(sticker_set->short_name_);
}
}
@ -8666,6 +8702,15 @@ void StickersManager::set_sticker_set_title(string short_name, string title, Pro
td_->create_handler<SetStickerSetTitleQuery>(std::move(promise))->send(short_name, title);
}
void StickersManager::delete_sticker_set(string short_name, 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"));
}
td_->create_handler<DeleteStickerSetQuery>(std::move(promise))->send(short_name);
}
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

@ -258,6 +258,8 @@ class StickersManager final : public Actor {
void on_update_move_sticker_set_to_top(StickerType sticker_type, StickerSetId sticker_set_id);
void on_sticker_set_deleted(const string &short_name);
std::pair<int32, vector<StickerSetId>> get_archived_sticker_sets(StickerType sticker_type,
StickerSetId offset_sticker_set_id, int32 limit,
bool force, Promise<Unit> &&promise);
@ -314,6 +316,8 @@ class StickersManager final : public Actor {
void set_sticker_set_title(string short_name, string title, Promise<Unit> &&promise);
void delete_sticker_set(string short_name, Promise<Unit> &&promise);
void set_sticker_position_in_set(const td_api::object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise);

View File

@ -7324,6 +7324,13 @@ void Td::on_request(uint64 id, td_api::setStickerSetTitle &request) {
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::deleteStickerSet &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.name_);
CREATE_OK_REQUEST_PROMISE();
stickers_manager_->delete_sticker_set(std::move(request.name_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setStickerPositionInSet &request) {
CHECK_IS_BOT();
CREATE_OK_REQUEST_PROMISE();

View File

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