Add td_api::getAllStickerEmojis.

This commit is contained in:
levlam 2023-09-04 16:17:36 +03:00
parent f4a8338232
commit 35ff6976d8
6 changed files with 82 additions and 0 deletions

View File

@ -8007,6 +8007,13 @@ getUserProfilePhotos user_id:int53 offset:int32 limit:int32 = ChatPhotos;
//@chat_id Chat identifier for which to return stickers. Available custom emoji stickers may be different for different chats //@chat_id Chat identifier for which to return stickers. Available custom emoji stickers may be different for different chats
getStickers sticker_type:StickerType query:string limit:int32 chat_id:int53 = Stickers; getStickers sticker_type:StickerType query:string limit:int32 chat_id:int53 = Stickers;
//@description Returns unique emoji that correspond to stickers to be found by the getStickers(sticker_type, query, 1000000, chat_id)
//@sticker_type Type of the stickers to search for
//@query Search query
//@chat_id Chat identifier for which to find stickers
//@return_only_main_emoji Pass true if only main emoji for each found sticker must be included in the result
getAllStickerEmojis sticker_type:StickerType query:string chat_id:int53 return_only_main_emoji:Bool = Emojis;
//@description Searches for stickers from public sticker sets that correspond to any of the given emoji //@description Searches for stickers from public sticker sets that correspond to any of the given emoji
//@sticker_type Type of the stickers to return //@sticker_type Type of the stickers to return
//@emojis Space-separated list of emoji to search for; must be non-empty //@emojis Space-separated list of emoji to search for; must be non-empty

View File

@ -2299,6 +2299,34 @@ tl_object_ptr<td_api::stickers> StickersManager::get_stickers_object(const vecto
transform(sticker_ids, [&](FileId sticker_id) { return get_sticker_object(sticker_id); })); transform(sticker_ids, [&](FileId sticker_id) { return get_sticker_object(sticker_id); }));
} }
td_api::object_ptr<td_api::emojis> StickersManager::get_sticker_emojis_object(const vector<FileId> &sticker_ids,
bool return_only_main_emoji) {
auto emojis = td_api::make_object<td_api::emojis>();
FlatHashSet<string> added_emojis;
auto add_emoji = [&](const string &emoji) {
if (!emoji.empty() && added_emojis.insert(emoji).second) {
emojis->emojis_.push_back(emoji);
}
};
for (auto sticker_id : sticker_ids) {
auto sticker = get_sticker(sticker_id);
CHECK(sticker != nullptr);
add_emoji(sticker->alt_);
if (!return_only_main_emoji && sticker->set_id_.is_valid()) {
const StickerSet *sticker_set = get_sticker_set(sticker->set_id_);
if (sticker_set != nullptr) {
auto it = sticker_set->sticker_emojis_map_.find(sticker_id);
if (it != sticker_set->sticker_emojis_map_.end()) {
for (auto emoji : it->second) {
add_emoji(emoji);
}
}
}
}
}
return emojis;
}
tl_object_ptr<td_api::DiceStickers> StickersManager::get_dice_stickers_object(const string &emoji, int32 value) const { tl_object_ptr<td_api::DiceStickers> StickersManager::get_dice_stickers_object(const string &emoji, int32 value) const {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
return nullptr; return nullptr;

View File

@ -81,6 +81,9 @@ class StickersManager final : public Actor {
tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const; tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const;
td_api::object_ptr<td_api::emojis> get_sticker_emojis_object(const vector<FileId> &sticker_ids,
bool return_only_main_emoji);
td_api::object_ptr<td_api::sticker> get_custom_emoji_sticker_object(CustomEmojiId custom_emoji_id); td_api::object_ptr<td_api::sticker> get_custom_emoji_sticker_object(CustomEmojiId custom_emoji_id);
tl_object_ptr<td_api::DiceStickers> get_dice_stickers_object(const string &emoji, int32 value) const; tl_object_ptr<td_api::DiceStickers> get_dice_stickers_object(const string &emoji, int32 value) const;

View File

@ -2004,6 +2004,35 @@ class GetStickersRequest final : public RequestActor<> {
} }
}; };
class GetAllStickerEmojisRequest final : public RequestActor<> {
StickerType sticker_type_;
string query_;
DialogId dialog_id_;
bool return_only_main_emoji_;
vector<FileId> sticker_ids_;
void do_run(Promise<Unit> &&promise) final {
sticker_ids_ = td_->stickers_manager_->get_stickers(sticker_type_, query_, 1000000, dialog_id_, get_tries() < 2,
std::move(promise));
}
void do_send_result() final {
send_result(td_->stickers_manager_->get_sticker_emojis_object(sticker_ids_, return_only_main_emoji_));
}
public:
GetAllStickerEmojisRequest(ActorShared<Td> td, uint64 request_id, StickerType sticker_type, string &&query,
int64 dialog_id, bool return_only_main_emoji)
: RequestActor(std::move(td), request_id)
, sticker_type_(sticker_type)
, query_(std::move(query))
, dialog_id_(dialog_id)
, return_only_main_emoji_(return_only_main_emoji) {
set_tries(4);
}
};
class GetInstalledStickerSetsRequest final : public RequestActor<> { class GetInstalledStickerSetsRequest final : public RequestActor<> {
StickerType sticker_type_; StickerType sticker_type_;
@ -7565,6 +7594,13 @@ void Td::on_request(uint64 id, td_api::getStickers &request) {
request.chat_id_); request.chat_id_);
} }
void Td::on_request(uint64 id, td_api::getAllStickerEmojis &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_);
CREATE_REQUEST(GetAllStickerEmojisRequest, get_sticker_type(request.sticker_type_), std::move(request.query_),
request.chat_id_, request.return_only_main_emoji_);
}
void Td::on_request(uint64 id, td_api::searchStickers &request) { void Td::on_request(uint64 id, td_api::searchStickers &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.emojis_); CLEAN_INPUT_STRING(request.emojis_);

View File

@ -1289,6 +1289,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::getStickers &request); void on_request(uint64 id, td_api::getStickers &request);
void on_request(uint64 id, td_api::getAllStickerEmojis &request);
void on_request(uint64 id, td_api::searchStickers &request); void on_request(uint64 id, td_api::searchStickers &request);
void on_request(uint64 id, const td_api::getPremiumStickers &request); void on_request(uint64 id, const td_api::getPremiumStickers &request);

View File

@ -3086,6 +3086,12 @@ class CliClient final : public Actor {
get_args(args, query); get_args(args, query);
send_request(td_api::make_object<td_api::getStickers>(as_sticker_type(op), query.query, query.limit, send_request(td_api::make_object<td_api::getStickers>(as_sticker_type(op), query.query, query.limit,
op == "gseeme" ? my_id_ : 0)); op == "gseeme" ? my_id_ : 0));
} else if (op == "gaser" || op == "gasem" || op == "gase" || op == "gaseme") {
string query;
bool return_only_main_emoji;
get_args(args, query, return_only_main_emoji);
send_request(td_api::make_object<td_api::getAllStickerEmojis>(
as_sticker_type(op), query, op == "gaseme" ? my_id_ : 0, return_only_main_emoji));
} else if (op == "sst" || op == "sstm" || op == "sste") { } else if (op == "sst" || op == "sstm" || op == "sste") {
SearchQuery query; SearchQuery query;
get_args(args, query); get_args(args, query);