Add sticker_type to getStickers.

This commit is contained in:
levlam 2022-07-24 14:53:48 +03:00
parent 99ae4ada88
commit 40b5b586e6
5 changed files with 23 additions and 19 deletions

View File

@ -5900,8 +5900,8 @@ sharePhoneNumber user_id:int53 = Ok;
getUserProfilePhotos user_id:int53 offset:int32 limit:int32 = ChatPhotos;
//@description Returns stickers from the installed sticker sets that correspond to a given emoji. If the emoji is non-empty, favorite and recently used stickers may also be returned @emoji String representation of emoji. If empty, returns all known installed stickers @limit The maximum number of stickers to be returned
getStickers emoji:string limit:int32 = Stickers;
//@description Returns stickers from the installed sticker sets that correspond to a given emoji. If the emoji is non-empty and sticker type is stickerTypeRegular, then favorite and recently used stickers may also be returned @sticker_type Type of the sticker sets to return @emoji String representation of emoji. If empty, returns all known installed stickers @limit The maximum number of stickers to be returned
getStickers sticker_type:StickerType emoji:string limit:int32 = Stickers;
//@description Searches for stickers from public sticker sets that correspond to a given emoji @emoji String representation of emoji; must be non-empty @limit The maximum number of stickers to be returned
searchStickers emoji:string limit:int32 = Stickers;

View File

@ -3759,20 +3759,21 @@ std::pair<vector<FileId>, vector<FileId>> StickersManager::split_stickers_by_pre
return {std::move(regular_sticker_ids), std::move(premium_sticker_ids)};
}
vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool force, Promise<Unit> &&promise) {
vector<FileId> StickersManager::get_stickers(StickerType sticker_type, string emoji, int32 limit, bool force,
Promise<Unit> &&promise) {
if (limit <= 0) {
promise.set_error(Status::Error(400, "Parameter limit must be positive"));
return {};
}
auto type = static_cast<int32>(StickerType::Regular);
auto type = static_cast<int32>(sticker_type);
if (!are_installed_sticker_sets_loaded_[type]) {
load_installed_sticker_sets(StickerType::Regular, std::move(promise));
load_installed_sticker_sets(sticker_type, std::move(promise));
return {};
}
remove_emoji_modifiers_in_place(emoji);
if (!emoji.empty()) {
if (!are_recent_stickers_loaded_[0]) {
if (!emoji.empty() && sticker_type == StickerType::Regular) {
if (!are_recent_stickers_loaded_[0 /*is_attached*/]) {
load_recent_stickers(false, std::move(promise));
return {};
}
@ -3782,7 +3783,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
}
/*
if (!are_featured_sticker_sets_loaded_[type]) {
load_featured_sticker_sets(StickerType::Regular, std::move(promise));
load_featured_sticker_sets(sticker_type, std::move(promise));
return {};
}
*/
@ -3804,7 +3805,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
}
vector<FileId> prepend_sticker_ids;
if (!emoji.empty()) {
if (!emoji.empty() && sticker_type == StickerType::Regular) {
prepend_sticker_ids.reserve(favorite_sticker_ids_.size() + recent_sticker_ids_[0].size());
append(prepend_sticker_ids, recent_sticker_ids_[0]);
for (auto sticker_id : favorite_sticker_ids_) {
@ -3979,7 +3980,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
break;
}
}
if (sorted.size() < limit_size_t) {
if (sorted.size() < limit_size_t && sticker_type == StickerType::Regular) {
auto premium_count = G()->shared_config().get_option_integer("stickers_premium_by_emoji_num", 0);
if (premium_count > 0) {
for (const auto &sticker_id : premium_sticker_ids) {

View File

@ -133,7 +133,7 @@ class StickersManager final : public Actor {
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail, int32 layer) const;
vector<FileId> get_stickers(string emoji, int32 limit, bool force, Promise<Unit> &&promise);
vector<FileId> get_stickers(StickerType sticker_type, string emoji, int32 limit, bool force, Promise<Unit> &&promise);
vector<FileId> search_stickers(string emoji, int32 limit, Promise<Unit> &&promise);

View File

@ -1983,13 +1983,15 @@ class GetScopeNotificationSettingsRequest final : public RequestActor<> {
};
class GetStickersRequest final : public RequestActor<> {
StickerType sticker_type_;
string emoji_;
int32 limit_;
vector<FileId> sticker_ids_;
void do_run(Promise<Unit> &&promise) final {
sticker_ids_ = td_->stickers_manager_->get_stickers(emoji_, limit_, get_tries() < 2, std::move(promise));
sticker_ids_ =
td_->stickers_manager_->get_stickers(sticker_type_, emoji_, limit_, get_tries() < 2, std::move(promise));
}
void do_send_result() final {
@ -1997,8 +1999,8 @@ class GetStickersRequest final : public RequestActor<> {
}
public:
GetStickersRequest(ActorShared<Td> td, uint64 request_id, string &&emoji, int32 limit)
: RequestActor(std::move(td), request_id), emoji_(std::move(emoji)), limit_(limit) {
GetStickersRequest(ActorShared<Td> td, uint64 request_id, StickerType sticker_type, string &&emoji, int32 limit)
: RequestActor(std::move(td), request_id), sticker_type_(sticker_type), emoji_(std::move(emoji)), limit_(limit) {
set_tries(5);
}
};
@ -6987,7 +6989,8 @@ void Td::on_request(uint64 id, td_api::closeSecretChat &request) {
void Td::on_request(uint64 id, td_api::getStickers &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.emoji_);
CREATE_REQUEST(GetStickersRequest, std::move(request.emoji_), request.limit_);
CREATE_REQUEST(GetStickersRequest, get_sticker_type(request.sticker_type_), std::move(request.emoji_),
request.limit_);
}
void Td::on_request(uint64 id, td_api::searchStickers &request) {

View File

@ -2610,10 +2610,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getUser>(user_id));
} else if (op == "gsu") {
send_request(td_api::make_object<td_api::getSupportUser>());
} else if (op == "gs") {
} else if (op == "gs" || op == "gsmm" || op == "gsee") {
SearchQuery query;
get_args(args, query);
send_request(td_api::make_object<td_api::getStickers>(query.query, query.limit));
send_request(td_api::make_object<td_api::getStickers>(as_sticker_type(op), query.query, query.limit));
} else if (op == "sst") {
SearchQuery query;
get_args(args, query);
@ -2623,7 +2623,7 @@ class CliClient final : public Actor {
get_args(args, sticker_set_id);
send_request(td_api::make_object<td_api::getStickerSet>(sticker_set_id));
} else if (op == "giss" || op == "gissm" || op == "gisse") {
send_request(td_api::make_object<td_api::getInstalledStickerSets>(as_sticker_type(args)));
send_request(td_api::make_object<td_api::getInstalledStickerSets>(as_sticker_type(op)));
} else if (op == "gass" || op == "gassm" || op == "gasse") {
int64 offset_sticker_set_id;
string limit;
@ -2902,7 +2902,7 @@ class CliClient final : public Actor {
string message_ids;
get_args(args, chat_id, message_ids);
send_request(td_api::make_object<td_api::getMessages>(chat_id, as_message_ids(message_ids)));
} else if (op == "gsm") {
} else if (op == "gcspm") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::getChatSponsoredMessage>(chat_id));