Add dup_story_content.

This commit is contained in:
levlam 2023-05-29 23:00:32 +03:00
parent a0fd771da8
commit 81053032d8
2 changed files with 48 additions and 0 deletions

View File

@ -255,6 +255,52 @@ unique_ptr<StoryContent> copy_story_content(const StoryContent *content) {
}
}
unique_ptr<StoryContent> dup_story_content(Td *td, const StoryContent *content) {
if (content == nullptr) {
return nullptr;
}
auto fix_file_id = [file_manager = td->file_manager_.get()](FileId file_id) {
return file_manager->dup_file_id(file_id, "dup_story_content");
};
switch (content->get_type()) {
case StoryContentType::Photo: {
const auto *old_content = static_cast<const StoryContentPhoto *>(content);
// Find 'i' or largest
PhotoSize photo_size;
for (const auto &size : old_content->photo_.photos) {
if (size.type == 'i') {
photo_size = size;
}
}
if (photo_size.type == 0) {
for (const auto &size : old_content->photo_.photos) {
if (photo_size.type == 0 || photo_size < size) {
photo_size = size;
}
}
}
photo_size.type = 'i';
photo_size.file_id = fix_file_id(photo_size.file_id);
auto result = make_unique<StoryContentPhoto>();
result->photo_.photos.push_back(std::move(photo_size));
return std::move(result);
}
case StoryContentType::Video: {
const auto *old_content = static_cast<const StoryContentVideo *>(content);
return make_unique<StoryContentVideo>(
td->videos_manager_->dup_video(fix_file_id(old_content->file_id_), old_content->file_id_), FileId());
}
case StoryContentType::Unsupported:
return nullptr;
default:
UNREACHABLE();
return nullptr;
}
}
td_api::object_ptr<td_api::StoryContent> get_story_content_object(Td *td, const StoryContent *content) {
CHECK(content != nullptr);
switch (content->get_type()) {

View File

@ -45,6 +45,8 @@ void merge_story_contents(Td *td, const StoryContent *old_content, StoryContent
unique_ptr<StoryContent> copy_story_content(const StoryContent *content);
unique_ptr<StoryContent> dup_story_content(Td *td, const StoryContent *content);
td_api::object_ptr<td_api::StoryContent> get_story_content_object(Td *td, const StoryContent *content);
FileId get_story_content_any_file_id(const Td *td, const StoryContent *content);