From 0b8c71419fa5cf35b6ee525fdd2cd6db3978341e Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 19 May 2023 23:25:52 +0300 Subject: [PATCH] Add StoryManager::on_get_stories. --- td/telegram/StoryManager.cpp | 34 ++++++++++++++++++++++++++++++++++ td/telegram/StoryManager.h | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 6e895bc98..5502f1e7b 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -14,6 +14,8 @@ #include "td/telegram/StoryContentType.h" #include "td/telegram/Td.h" +#include "td/utils/logging.h" + namespace td { StoryManager::StoryManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { @@ -85,6 +87,7 @@ StoryId StoryManager::on_get_story(DialogId owner_dialog_id, CHECK(story_item != nullptr); StoryId story_id(story_item->id_); if (!story_id.is_valid() || is_local_story_id(story_id)) { + LOG(ERROR) << "Receive " << to_string(story_item); return StoryId(); } @@ -142,4 +145,35 @@ StoryId StoryManager::on_get_story(DialogId owner_dialog_id, return story_id; } +std::pair> StoryManager::on_get_stories( + DialogId owner_dialog_id, telegram_api::object_ptr &&stories) { + td_->contacts_manager_->on_get_users(std::move(stories->users_), "on_get_stories"); + vector story_ids; + for (auto &story : stories->stories_) { + switch (story->get_id()) { + case telegram_api::storyItemDeleted::ID: + LOG(ERROR) << "Receive storyItemDeleted"; + break; + case telegram_api::storyItemSkipped::ID: + LOG(ERROR) << "Receive storyItemSkipped"; + break; + case telegram_api::storyItem::ID: { + auto story_id = on_get_story(owner_dialog_id, telegram_api::move_object_as(story)); + if (story_id.is_valid()) { + story_ids.push_back(story_id); + } + break; + } + default: + UNREACHABLE(); + } + } + auto total_count = stories->count_; + if (total_count < static_cast(story_ids.size())) { + LOG(ERROR) << "Expected at most " << total_count << " stories, but receive " << story_ids.size(); + total_count = static_cast(story_ids.size()); + } + return {total_count, std::move(story_ids)}; +} + } // namespace td diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 794d95b8f..62998e6a8 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -21,6 +21,8 @@ #include "td/utils/common.h" #include "td/utils/WaitFreeHashMap.h" +#include + namespace td { class StoryContent; @@ -37,6 +39,9 @@ class StoryManager final : public Actor { StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item); + std::pair> on_get_stories(DialogId owner_dialog_id, + telegram_api::object_ptr &&stories); + td_api::object_ptr get_story_object(StoryFullId story_full_id) const; private: