Add td_api::getOwnedStickerSets.

This commit is contained in:
levlam 2024-03-20 15:41:49 +03:00
parent 1c029b8b54
commit 22d2f6a98d
6 changed files with 105 additions and 2 deletions

View File

@ -9296,7 +9296,10 @@ getPremiumStickers limit:int32 = Stickers;
//@description Returns a list of installed sticker sets @sticker_type Type of the sticker sets to return
getInstalledStickerSets sticker_type:StickerType = StickerSets;
//@description Returns a list of archived sticker sets @sticker_type Type of the sticker sets to return @offset_sticker_set_id Identifier of the sticker set from which to return the result @limit The maximum number of sticker sets to return; up to 100
//@description Returns a list of archived sticker sets
//@sticker_type Type of the sticker sets to return
//@offset_sticker_set_id Identifier of the sticker set from which to return the result; use 0 to get results from the beginning
//@limit The maximum number of sticker sets to return; up to 100
getArchivedStickerSets sticker_type:StickerType offset_sticker_set_id:int64 limit:int32 = StickerSets;
//@description Returns a list of trending sticker sets. For optimal performance, the number of returned sticker sets is chosen by TDLib
@ -10156,6 +10159,11 @@ setStickerKeywords sticker:InputFile keywords:vector<string> = Ok;
//@mask_position Position where the mask is placed; pass null to remove mask position
setStickerMaskPosition sticker:InputFile mask_position:maskPosition = Ok;
//@description Returns sticker sets owned by the current user
//@offset_sticker_set_id Identifier of the sticker set from which to return owned sticker sets; use 0 to get results from the beginning
//@limit The maximum number of sticker sets to be returned; must be positive and can't be greater than 100. For optimal performance, the number of returned objects is chosen by TDLib and can be smaller than the specified limit
getOwnedStickerSets offset_sticker_set_id:int64 limit:int32 = StickerSets;
//@description Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded
//@location Location of the map center

View File

@ -1386,6 +1386,35 @@ class ChangeStickerQuery final : public Td::ResultHandler {
}
};
class GetMyStickersQuery final : public Td::ResultHandler {
Promise<telegram_api::object_ptr<telegram_api::messages_myStickers>> promise_;
public:
explicit GetMyStickersQuery(Promise<telegram_api::object_ptr<telegram_api::messages_myStickers>> &&promise)
: promise_(std::move(promise)) {
}
void send(StickerSetId offset_sticker_set_id, int32 limit) {
send_query(
G()->net_query_creator().create(telegram_api::messages_getMyStickers(offset_sticker_set_id.get(), limit)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_getMyStickers>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetMyStickersQuery: " << to_string(ptr);
promise_.set_value(std::move(ptr));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetCustomEmojiDocumentsQuery final : public Td::ResultHandler {
Promise<vector<telegram_api::object_ptr<telegram_api::Document>>> promise_;
@ -3645,7 +3674,7 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
s->sticker_type_ = sticker_type;
s->has_text_color_ = has_text_color;
s->channel_emoji_status_ = channel_emoji_status;
s->is_created_ = is_official;
s->is_created_ = is_created;
s->is_changed_ = true;
} else {
CHECK(s->id_ == set_id);
@ -8561,6 +8590,52 @@ void StickersManager::set_sticker_mask_position(const td_api::object_ptr<td_api:
StickerMaskPosition(mask_position), false, string());
}
void StickersManager::get_created_sticker_sets(StickerSetId offset_sticker_set_id, int32 limit,
Promise<td_api::object_ptr<td_api::stickerSets>> &&promise) {
if (limit <= 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
}
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::messages_myStickers>> r_my_stickers) mutable {
send_closure(actor_id, &StickersManager::on_get_created_sticker_sets, std::move(r_my_stickers),
std::move(promise));
});
td_->create_handler<GetMyStickersQuery>(std::move(query_promise))->send(offset_sticker_set_id, limit);
}
void StickersManager::on_get_created_sticker_sets(
Result<telegram_api::object_ptr<telegram_api::messages_myStickers>> r_my_stickers,
Promise<td_api::object_ptr<td_api::stickerSets>> &&promise) {
G()->ignore_result_if_closing(r_my_stickers);
if (r_my_stickers.is_error()) {
return promise.set_error(r_my_stickers.move_as_error());
}
auto my_stickers = r_my_stickers.move_as_ok();
auto total_count = my_stickers->count_;
vector<StickerSetId> sticker_set_ids;
for (auto &sticker_set_covered : my_stickers->sets_) {
auto sticker_set_id =
on_get_sticker_set_covered(std::move(sticker_set_covered), false, "on_get_created_sticker_sets");
if (sticker_set_id.is_valid()) {
auto sticker_set = get_sticker_set(sticker_set_id);
CHECK(sticker_set != nullptr);
update_sticker_set(sticker_set, "on_get_created_sticker_sets");
if (!td::contains(sticker_set_ids, sticker_set_id) && sticker_set->is_created_) {
sticker_set_ids.push_back(sticker_set_id);
}
}
}
if (static_cast<int32>(sticker_set_ids.size()) > total_count) {
LOG(ERROR) << "Expected total of " << total_count << " owned sticker sets, but " << sticker_set_ids.size()
<< " received";
total_count = static_cast<int32>(sticker_set_ids.size());
}
send_update_installed_sticker_sets();
promise.set_value(get_sticker_sets_object(total_count, sticker_set_ids, 1));
}
vector<FileId> StickersManager::get_attached_sticker_file_ids(const vector<int32> &int_file_ids) {
vector<FileId> result;

View File

@ -320,6 +320,9 @@ class StickersManager final : public Actor {
void set_sticker_mask_position(const td_api::object_ptr<td_api::InputFile> &sticker,
td_api::object_ptr<td_api::maskPosition> &&mask_position, Promise<Unit> &&promise);
void get_created_sticker_sets(StickerSetId offset_sticker_set_id, int32 limit,
Promise<td_api::object_ptr<td_api::stickerSets>> &&promise);
vector<FileId> get_recent_stickers(bool is_attached, Promise<Unit> &&promise);
void on_get_recent_stickers(bool is_repair, bool is_attached,
@ -835,6 +838,9 @@ class StickersManager final : public Actor {
};
Result<StickerInputDocument> get_sticker_input_document(const tl_object_ptr<td_api::InputFile> &sticker) const;
void on_get_created_sticker_sets(Result<telegram_api::object_ptr<telegram_api::messages_myStickers>> r_my_stickers,
Promise<td_api::object_ptr<td_api::stickerSets>> &&promise);
bool update_sticker_set_cache(const StickerSet *sticker_set, Promise<Unit> &promise);
const StickerSet *get_premium_gift_sticker_set();

View File

@ -8292,6 +8292,13 @@ void Td::on_request(uint64 id, td_api::setStickerMaskPosition &request) {
stickers_manager_->set_sticker_mask_position(request.sticker_, std::move(request.mask_position_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getOwnedStickerSets &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
stickers_manager_->get_created_sticker_sets(StickerSetId(request.offset_sticker_set_id_), request.limit_,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getRecentStickers &request) {
CHECK_IS_USER();
CREATE_REQUEST(GetRecentStickersRequest, request.is_attached_);

View File

@ -1526,6 +1526,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setStickerMaskPosition &request);
void on_request(uint64 id, const td_api::getOwnedStickerSets &request);
void on_request(uint64 id, const td_api::getRecentStickers &request);
void on_request(uint64 id, td_api::addRecentSticker &request);

View File

@ -3522,6 +3522,11 @@ class CliClient final : public Actor {
});
send_request(td_api::make_object<td_api::createNewStickerSet>(my_id_, title, name, as_sticker_type(op), false,
std::move(input_stickers), "tg_cli"));
} else if (op == "goss") {
int64 sticker_set_id;
string limit;
get_args(args, sticker_set_id, limit);
send_request(td_api::make_object<td_api::getOwnedStickerSets>(sticker_set_id, as_limit(limit)));
} else if (op == "sss") {
send_request(td_api::make_object<td_api::searchStickerSet>(args));
} else if (op == "siss") {