Add StoryManager::delete_story_files.

This commit is contained in:
levlam 2023-05-19 17:00:33 +03:00
parent 88620d1347
commit 8c9bf81359
4 changed files with 39 additions and 0 deletions

View File

@ -188,4 +188,21 @@ td_api::object_ptr<td_api::StoryContent> get_story_content_object(Td *td, const
}
}
vector<FileId> 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<const StoryContentPhoto *>(content)->photo_);
case StoryContentType::Video: {
vector<FileId> result;
const auto *s = static_cast<const StoryContentVideo *>(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

View File

@ -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<td_api::StoryContent> get_story_content_object(Td *td, const StoryContent *content);
vector<FileId> get_story_content_file_ids(const Td *td, const StoryContent *content);
} // namespace td

View File

@ -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<td_api::story> StoryManager::get_story_object(StoryFullId sto
get_formatted_text_object(story->caption_, true, -1));
}
vector<FileId> 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<Unit>(), "delete_story_files");
}
}
StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
telegram_api::object_ptr<telegram_api::storyItem> &&story_item) {
CHECK(story_item != nullptr);

View File

@ -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<td_api::story> get_story_object(StoryFullId story_full_id, const Story *story) const;
vector<FileId> 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<StoryFullId, unique_ptr<Story>, StoryFullIdHash> stories_;