From e169cfc7f7eb8dd453b83d8072e618011318ad7a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 29 May 2023 20:48:31 +0300 Subject: [PATCH] Add copy_story_content function. --- td/telegram/StoryContent.cpp | 23 +++++++++++++++++++++++ td/telegram/StoryContent.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index 3501e2e5d..1f1f64777 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -232,6 +232,29 @@ void merge_story_contents(Td *td, const StoryContent *old_content, StoryContent } } +unique_ptr copy_story_content(const StoryContent *content) { + if (content == nullptr) { + return nullptr; + } + switch (content->get_type()) { + case StoryContentType::Photo: { + const auto *story_content = static_cast(content); + return make_unique(Photo(story_content->photo_)); + } + case StoryContentType::Video: { + const auto *story_content = static_cast(content); + return make_unique(story_content->file_id_, story_content->alt_file_id_); + } + case StoryContentType::Unsupported: { + const auto *story_content = static_cast(content); + return make_unique(story_content->version_); + } + default: + UNREACHABLE(); + return nullptr; + } +} + td_api::object_ptr get_story_content_object(Td *td, const StoryContent *content) { CHECK(content != nullptr); switch (content->get_type()) { diff --git a/td/telegram/StoryContent.h b/td/telegram/StoryContent.h index 75da89a6c..9b38e2a97 100644 --- a/td/telegram/StoryContent.h +++ b/td/telegram/StoryContent.h @@ -43,6 +43,8 @@ telegram_api::object_ptr get_story_content_input_media void merge_story_contents(Td *td, const StoryContent *old_content, StoryContent *new_content, DialogId dialog_id, bool need_merge_files, bool &is_content_changed, bool &need_update); +unique_ptr copy_story_content(const StoryContent *content); + td_api::object_ptr get_story_content_object(Td *td, const StoryContent *content); FileId get_story_content_any_file_id(const Td *td, const StoryContent *content);