From 20901b6ac562ad42d2ac597aa335fa2017f4b8dc Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 9 Jun 2023 17:21:34 +0300 Subject: [PATCH] Add td_api::getArchivedStories. --- td/generate/scheme/td_api.tl | 11 +++++-- td/telegram/StoryManager.cpp | 59 ++++++++++++++++++++++++++++++++++++ td/telegram/StoryManager.h | 5 +++ td/telegram/Td.cpp | 10 ++++-- td/telegram/Td.h | 4 ++- td/telegram/cli.cpp | 5 +++ 6 files changed, 89 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 094d72a2a..4865941ab 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7224,6 +7224,9 @@ deleteStory story_id:int32 = Ok; //@description Toggles whether stories of the user are available on the main chat list @user_id Identifier of the user @are_archived Pass true to make the story unavailable on the main chat list; pass false to make them available toggleUserStoriesAreArchived user_id:int53 are_archived:Bool = Ok; +//@description Returns the list of expiring stories of a given user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id) @user_id User identifier +getUserExpiringStories user_id:int53 = Stories; + //@description Returns the list of pinned stories of a given user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). //-For optimal performance, the number of returned stories is chosen by TDLib //@user_id User identifier @@ -7232,8 +7235,12 @@ toggleUserStoriesAreArchived user_id:int53 are_archived:Bool = Ok; //-For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit getUserPinnedStories user_id:int53 from_story_id:int32 limit:int32 = Stories; -//@description Returns the list of expiring stories of a given user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id) @user_id User identifier -getUserExpiringStories user_id:int53 = Stories; +//@description Returns the list of all stories of the current user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). +//-For optimal performance, the number of returned stories is chosen by TDLib +//@from_story_id Identifier of the story starting from which stories must be returned; use 0 to get results from the last story +//@limit The maximum number of stories to be returned +//-For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit +getArchivedStories from_story_id:int32 limit:int32 = Stories; //@description Returns information about a bot that can be added to attachment menu @bot_user_id Bot's user identifier diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 1947802cf..7f777286f 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -141,6 +141,34 @@ class GetPinnedStoriesQuery final : public Td::ResultHandler { } }; +class GetStoriesArchiveQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetStoriesArchiveQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(StoryId offset_story_id, int32 limit) { + send_query(G()->net_query_creator().create(telegram_api::stories_getStoriesArchive(offset_story_id.get(), limit))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto result = result_ptr.move_as_ok(); + LOG(DEBUG) << "Receive result for GetStoriesArchiveQuery: " << to_string(result); + promise_.set_value(std::move(result)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetUserStoriesQuery final : public Td::ResultHandler { Promise> promise_; @@ -512,6 +540,37 @@ void StoryManager::on_get_dialog_pinned_stories(DialogId owner_dialog_id, }))); } +void StoryManager::get_story_archive(StoryId from_story_id, int32 limit, + Promise> &&promise) { + if (limit <= 0) { + return promise.set_error(Status::Error(400, "Parameter limit must be positive")); + } + + if (from_story_id != StoryId() && !from_story_id.is_server()) { + return promise.set_error(Status::Error(400, "Invalid value of parameter from_story_id specified")); + } + + auto query_promise = + PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)]( + Result> &&result) mutable { + if (result.is_error()) { + return promise.set_error(result.move_as_error()); + } + send_closure(actor_id, &StoryManager::on_get_story_archive, result.move_as_ok(), std::move(promise)); + }); + td_->create_handler(std::move(query_promise))->send(from_story_id, limit); +} + +void StoryManager::on_get_story_archive(telegram_api::object_ptr &&stories, + Promise> &&promise) { + TRY_STATUS_PROMISE(promise, G()->close_status()); + DialogId dialog_id(td_->contacts_manager_->get_my_id()); + auto result = on_get_stories(dialog_id, {}, std::move(stories)); + promise.set_value(get_stories_object(result.first, transform(result.second, [dialog_id](StoryId story_id) { + return StoryFullId(dialog_id, story_id); + }))); +} + void StoryManager::get_dialog_expiring_stories(DialogId owner_dialog_id, Promise> &&promise) { if (!td_->messages_manager_->have_dialog_info_force(owner_dialog_id)) { diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 2ee3709c3..0c6e6109f 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -99,6 +99,8 @@ class StoryManager final : public Actor { void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, Promise> &&promise); + void get_story_archive(StoryId from_story_id, int32 limit, Promise> &&promise); + void get_dialog_expiring_stories(DialogId owner_dialog_id, Promise> &&promise); void on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item_ptr); @@ -154,6 +156,9 @@ class StoryManager final : public Actor { telegram_api::object_ptr &&stories, Promise> &&promise); + void on_get_story_archive(telegram_api::object_ptr &&stories, + Promise> &&promise); + void on_get_dialog_expiring_stories(DialogId owner_dialog_id, telegram_api::object_ptr &&stories, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d960dc99a..b36a221ad 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6424,6 +6424,12 @@ void Td::on_request(uint64 id, const td_api::readChatList &request) { messages_manager_->read_all_dialogs_from_list(DialogListId(request.chat_list_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getUserExpiringStories &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + story_manager_->get_dialog_expiring_stories(DialogId(UserId(request.user_id_)), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getUserPinnedStories &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); @@ -6431,10 +6437,10 @@ void Td::on_request(uint64 id, const td_api::getUserPinnedStories &request) { request.limit_, std::move(promise)); } -void Td::on_request(uint64 id, const td_api::getUserExpiringStories &request) { +void Td::on_request(uint64 id, const td_api::getArchivedStories &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); - story_manager_->get_dialog_expiring_stories(DialogId(UserId(request.user_id_)), std::move(promise)); + story_manager_->get_story_archive(StoryId(request.from_story_id_), request.limit_, std::move(promise)); } void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 13182ca59..c02e37270 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1000,9 +1000,11 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::readChatList &request); + void on_request(uint64 id, const td_api::getUserExpiringStories &request); + void on_request(uint64 id, const td_api::getUserPinnedStories &request); - void on_request(uint64 id, const td_api::getUserExpiringStories &request); + void on_request(uint64 id, const td_api::getArchivedStories &request); void on_request(uint64 id, const td_api::getAttachmentMenuBot &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 89377f1db..27b383b07 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4049,6 +4049,11 @@ class CliClient final : public Actor { string limit; get_args(args, user_id, from_story_id, limit); send_request(td_api::make_object(user_id, from_story_id, as_limit(limit))); + } else if (op == "gast") { + StoryId from_story_id; + string limit; + get_args(args, from_story_id, limit); + send_request(td_api::make_object(from_story_id, as_limit(limit))); } else if (op == "gues") { UserId user_id; get_args(args, user_id);