diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index d6ae450da..a4943445a 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -188,4 +188,21 @@ td_api::object_ptr get_story_content_object(Td *td, const } } +vector get_story_content_file_ids(const Td *td, const StoryContent *content) { + switch (content->get_type()) { + case StoryContentType::Photo: + return photo_get_file_ids(static_cast(content)->photo_); + case StoryContentType::Video: { + vector result; + const auto *s = static_cast(content); + Document(Document::Type::Video, s->file_id_).append_file_ids(td, result); + Document(Document::Type::Video, s->alt_file_id_).append_file_ids(td, result); + return result; + } + case StoryContentType::Unsupported: + default: + return {}; + } +} + } // namespace td diff --git a/td/telegram/StoryContent.h b/td/telegram/StoryContent.h index 82634cb45..83b477d83 100644 --- a/td/telegram/StoryContent.h +++ b/td/telegram/StoryContent.h @@ -7,10 +7,13 @@ #pragma once #include "td/telegram/DialogId.h" +#include "td/telegram/files/FileId.h" #include "td/telegram/StoryContentType.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" +#include "td/utils/common.h" + namespace td { class Td; @@ -35,4 +38,6 @@ void merge_story_contents(Td *td, const StoryContent *old_content, StoryContent td_api::object_ptr get_story_content_object(Td *td, const StoryContent *content); +vector get_story_content_file_ids(const Td *td, const StoryContent *content); + } // namespace td diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index ee6bd2de2..6e895bc98 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -8,6 +8,7 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/ContactsManager.h" +#include "td/telegram/files/FileManager.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/StoryContent.h" #include "td/telegram/StoryContentType.h" @@ -68,6 +69,17 @@ td_api::object_ptr StoryManager::get_story_object(StoryFullId sto get_formatted_text_object(story->caption_, true, -1)); } +vector StoryManager::get_story_file_ids(const Story *story) const { + CHECK(story != nullptr); + return get_story_content_file_ids(td_, story->content_.get()); +} + +void StoryManager::delete_story_files(const Story *story) const { + for (auto file_id : get_story_file_ids(story)) { + send_closure(G()->file_manager(), &FileManager::delete_file, file_id, Promise(), "delete_story_files"); + } +} + StoryId StoryManager::on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item) { CHECK(story_item != nullptr); diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 0533096d7..794d95b8f 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/DialogId.h" +#include "td/telegram/files/FileId.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/StoryFullId.h" #include "td/telegram/StoryId.h" @@ -61,6 +62,10 @@ class StoryManager final : public Actor { td_api::object_ptr get_story_object(StoryFullId story_full_id, const Story *story) const; + vector get_story_file_ids(const Story *story) const; + + void delete_story_files(const Story *story) const; + static bool is_local_story_id(StoryId story_id); WaitFreeHashMap, StoryFullIdHash> stories_;