diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1a061097b..39e1458de 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7259,6 +7259,11 @@ getUserPinnedStories user_id:int53 from_story_id:int32 limit:int32 = Stories; //-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 Informs TDLib that a story is opened and is being viewed by the user +//@story_sender_user_id The identifier of the sender of the opened story +//@story_id The identifier of the story +openStory story_sender_user_id:int53 story_id:int32 = Ok; + //@description Returns information about a bot that can be added to attachment menu @bot_user_id Bot's user identifier getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index e33791004..32cf1e3e5 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -610,6 +610,30 @@ void StoryManager::on_get_dialog_expiring_stories(DialogId owner_dialog_id, }))); } +void StoryManager::open_story(DialogId owner_dialog_id, StoryId story_id, Promise &&promise) { + if (!td_->messages_manager_->have_dialog_info_force(owner_dialog_id)) { + return promise.set_error(Status::Error(400, "Story sender not found")); + } + if (!td_->messages_manager_->have_input_peer(owner_dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access the story sender")); + } + if (!story_id.is_valid()) { + return promise.set_error(Status::Error(400, "Invalid story identifier specified")); + } + + StoryFullId story_full_id{owner_dialog_id, story_id}; + const Story *story = get_story(story_full_id); + if (story == nullptr) { + return promise.set_value(Unit()); + } + + for (auto file_id : get_story_file_ids(story)) { + td_->file_manager_->check_local_location_async(file_id, true); + } + + promise.set_value(Unit()); +} + bool StoryManager::have_story(StoryFullId story_full_id) const { return get_story(story_full_id) != nullptr; } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 1b9da4b11..a8a1e91ef 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -104,6 +104,8 @@ class StoryManager final : public Actor { void get_dialog_expiring_stories(DialogId owner_dialog_id, Promise> &&promise); + void open_story(DialogId owner_dialog_id, StoryId story_id, Promise &&promise); + StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item_ptr); std::pair> on_get_stories(DialogId owner_dialog_id, vector &&expected_story_ids, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9728ef652..d46d00c47 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6443,6 +6443,13 @@ void Td::on_request(uint64 id, const td_api::getArchivedStories &request) { story_manager_->get_story_archive(StoryId(request.from_story_id_), request.limit_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::openStory &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + story_manager_->open_story(DialogId(UserId(request.story_sender_user_id_)), StoryId(request.story_id_), + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 8c052a23b..aca1c97bb 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1006,6 +1006,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getArchivedStories &request); + void on_request(uint64 id, const td_api::openStory &request); + void on_request(uint64 id, const td_api::getAttachmentMenuBot &request); void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index e8875ea05..93d5843e7 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4058,6 +4058,11 @@ class CliClient final : public Actor { UserId user_id; get_args(args, user_id); send_request(td_api::make_object(user_id)); + } else if (op == "os") { + UserId story_sender_user_id; + StoryId story_id; + get_args(args, story_sender_user_id, story_id); + send_request(td_api::make_object(story_sender_user_id, story_id)); } else if (op == "gamb") { UserId user_id; get_args(args, user_id);