Add td_api::checkStickerSetName.

This commit is contained in:
levlam 2021-06-17 21:29:07 +03:00
parent 706647bdbc
commit 84cf82583e
7 changed files with 107 additions and 3 deletions

View File

@ -280,7 +280,7 @@ function split_file($file, $chunks, $undo) {
'auth_manager[_(-][^.]|AuthManager' => 'AuthManager',
'background_manager[_(-][^.]|BackgroundManager' => "BackgroundManager",
'ConfigShared|shared_config[(]' => 'ConfigShared',
'contacts_manager[_(-][^.]|ContactsManager([^ ;.]| [^*])' => 'ContactsManager',
'contacts_manager[_(-][^.]|ContactsManager([^ ;.]| [^*])|BotData|ChannelType|CheckDialogUsernameResult|CanTransferOwnershipResult' => 'ContactsManager',
'country_info_manager[_(-][^.]|CountryInfoManager' => 'CountryInfoManager',
'documents_manager[_(-][^.]|DocumentsManager' => "DocumentsManager",
'file_reference_manager[_(-][^.]|FileReferenceManager|file_references[)]' => 'FileReferenceManager',
@ -300,7 +300,7 @@ function split_file($file, $chunks, $undo) {
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
'SecretChatActor' => 'SecretChatActor',
'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',
'stickers_manager[_(-][^.]|StickersManager|CheckStickerSetNameResult' => 'StickersManager',
'[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb',
'TopDialogCategory|get_top_dialog_category' => 'TopDialogCategory',
'top_dialog_manager[_(-][^.]|TopDialogManager' => 'TopDialogManager',

View File

@ -2706,6 +2706,18 @@ checkChatUsernameResultPublicChatsTooMuch = CheckChatUsernameResult;
checkChatUsernameResultPublicGroupsUnavailable = CheckChatUsernameResult;
//@class CheckStickerSetNameResult @description Represents result of checking whether a name can be used for a new sticker set
//@description The name can be set
checkStickerSetNameResultOk = CheckStickerSetNameResult;
//@description The name is invalid
checkStickerSetNameResultNameInvalid = CheckStickerSetNameResult;
//@description The name is occupied
checkStickerSetNameResultNameOccupied = CheckStickerSetNameResult;
//@class MessageFileType @description Contains information about a file with messages exported from another app
//@description The messages was exported from a private chat @name Name of the other party; may be empty if unrecognized
@ -3990,7 +4002,7 @@ removeRecentlyFoundChat chat_id:int53 = Ok;
//@description Clears the list of recently found chats
clearRecentlyFoundChats = Ok;
//@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if chat is being created @username Username to be checked
//@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if the chat is being created @username Username to be checked
checkChatUsername chat_id:int53 username:string = CheckChatUsernameResult;
//@description Returns a list of public chats of the specified type, owned by the user @type Type of the public chats to return
@ -5306,6 +5318,9 @@ uploadStickerFile user_id:int32 png_sticker:InputFile = File;
//@description Returns a suggested name for a new sticker set with a given title @title Sticker set title; 1-64 characters
getSuggestedStickerSetName title:string = Text;
//@description Checks whether a name can be used for a new sticker set @name Name to be checked
checkStickerSetName name:string = CheckStickerSetNameResult;
//@description Creates a new sticker set. Returns the newly created sticker set
//@user_id Sticker set owner; ignored for regular users
//@title Sticker set title; 1-64 characters

View File

@ -928,6 +928,31 @@ class SuggestStickerSetShortNameQuery : public Td::ResultHandler {
}
};
class CheckStickerSetShortNameQuery : public Td::ResultHandler {
Promise<bool> promise_;
public:
explicit CheckStickerSetShortNameQuery(Promise<bool> &&promise) : promise_(std::move(promise)) {
}
void send(const string &short_name) {
send_query(G()->net_query_creator().create(telegram_api::stickers_checkShortName(short_name)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::stickers_checkShortName>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
class CreateNewStickerSetQuery : public Td::ResultHandler {
Promise<Unit> promise_;
@ -4754,6 +4779,44 @@ void StickersManager::get_suggested_sticker_set_name(string title, Promise<strin
td_->create_handler<SuggestStickerSetShortNameQuery>(std::move(promise))->send(title);
}
void StickersManager::check_sticker_set_name(const string &name, Promise<CheckStickerSetNameResult> &&promise) {
if (name.empty()) {
return promise.set_value(CheckStickerSetNameResult::Invalid);
}
auto request_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<bool> result) mutable {
if (result.is_error()) {
auto error = result.move_as_error();
if (error.message() == "SHORT_NAME_INVALID") {
return promise.set_value(CheckStickerSetNameResult::Invalid);
}
if (error.message() == "SHORT_NAME_OCCUPIED") {
return promise.set_value(CheckStickerSetNameResult::Occupied);
}
return promise.set_error(std::move(error));
}
promise.set_value(CheckStickerSetNameResult::Ok);
});
return td_->create_handler<CheckStickerSetShortNameQuery>(std::move(request_promise))->send(name);
}
td_api::object_ptr<td_api::CheckStickerSetNameResult> StickersManager::get_check_sticker_set_name_result_object(
CheckStickerSetNameResult result) {
switch (result) {
case CheckStickerSetNameResult::Ok:
return td_api::make_object<td_api::checkStickerSetNameResultOk>();
case CheckStickerSetNameResult::Invalid:
return td_api::make_object<td_api::checkStickerSetNameResultNameInvalid>();
case CheckStickerSetNameResult::Occupied:
return td_api::make_object<td_api::checkStickerSetNameResultNameOccupied>();
default:
UNREACHABLE();
return nullptr;
}
}
void StickersManager::create_new_sticker_set(UserId user_id, string &title, string &short_name, bool is_masks,
vector<tl_object_ptr<td_api::InputSticker>> &&stickers,
Promise<Unit> &&promise) {

View File

@ -38,6 +38,8 @@ namespace td {
class Td;
enum class CheckStickerSetNameResult : uint8 { Ok, Invalid, Occupied };
class StickersManager : public Actor {
public:
static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001;
@ -167,6 +169,11 @@ class StickersManager : public Actor {
void get_suggested_sticker_set_name(string short_name, Promise<string> &&promise);
void check_sticker_set_name(const string &name, Promise<CheckStickerSetNameResult> &&promise);
static td_api::object_ptr<td_api::CheckStickerSetNameResult> get_check_sticker_set_name_result_object(
CheckStickerSetNameResult result);
void create_new_sticker_set(UserId user_id, string &title, string &short_name, bool is_masks,
vector<tl_object_ptr<td_api::InputSticker>> &&stickers, Promise<Unit> &&promise);

View File

@ -7051,6 +7051,20 @@ void Td::on_request(uint64 id, td_api::getSuggestedStickerSetName &request) {
stickers_manager_->get_suggested_sticker_set_name(std::move(request.title_), std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::checkStickerSetName &request) {
CLEAN_INPUT_STRING(request.name_);
CREATE_REQUEST_PROMISE();
auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<CheckStickerSetNameResult> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(StickersManager::get_check_sticker_set_name_result_object(result.ok()));
}
});
stickers_manager_->check_sticker_set_name(request.name_, std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::createNewStickerSet &request) {
CLEAN_INPUT_STRING(request.title_);
CLEAN_INPUT_STRING(request.name_);

View File

@ -976,6 +976,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::getSuggestedStickerSetName &request);
void on_request(uint64 id, td_api::checkStickerSetName &request);
void on_request(uint64 id, td_api::createNewStickerSet &request);
void on_request(uint64 id, td_api::addStickerToSet &request);

View File

@ -2415,6 +2415,9 @@ class CliClient final : public Actor {
} else if (op == "gsssn") {
string title = args;
send_request(td_api::make_object<td_api::getSuggestedStickerSetName>(title));
} else if (op == "cssn") {
string name = args;
send_request(td_api::make_object<td_api::checkStickerSetName>(name));
} else if (op == "cnss") {
string title;
string name;