Add get_web_page_file_ids method.
GitOrigin-RevId: f25119ed147005068f9ff709813ba10e8810fc57
This commit is contained in:
parent
73d09e1816
commit
e8d3674eb4
@ -17,6 +17,7 @@
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/DocumentsManager.h"
|
||||
#include "td/telegram/DocumentsManager.hpp"
|
||||
#include "td/telegram/files/FileId.h"
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
#include "td/telegram/files/FileManager.hpp"
|
||||
#include "td/telegram/Global.h"
|
||||
@ -449,6 +450,10 @@ class WebPagesManager::PageBlock {
|
||||
|
||||
virtual Type get_type() const = 0;
|
||||
|
||||
virtual vector<FileId> get_file_ids() const {
|
||||
return vector<FileId>();
|
||||
}
|
||||
|
||||
virtual tl_object_ptr<td_api::PageBlock> get_page_block_object() const = 0;
|
||||
|
||||
PageBlock() = default;
|
||||
@ -888,6 +893,19 @@ class WebPagesManager::PageBlockAnimation : public PageBlock {
|
||||
return Type::Animation;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result;
|
||||
if (animation_file_id.is_valid()) {
|
||||
result.push_back(animation_file_id);
|
||||
auto thumbnail_file_id =
|
||||
G()->td().get_actor_unsafe()->animations_manager_->get_animation_thumbnail_file_id(animation_file_id);
|
||||
if (thumbnail_file_id.is_valid()) {
|
||||
result.push_back(thumbnail_file_id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockAnimation>(
|
||||
G()->td().get_actor_unsafe()->animations_manager_->get_animation_object(animation_file_id,
|
||||
@ -948,6 +966,10 @@ class WebPagesManager::PageBlockPhoto : public PageBlock {
|
||||
return Type::Photo;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
return photo_get_file_ids(photo);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockPhoto>(
|
||||
get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &photo), get_rich_text_object(caption));
|
||||
@ -984,6 +1006,19 @@ class WebPagesManager::PageBlockVideo : public PageBlock {
|
||||
return Type::Video;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result;
|
||||
if (video_file_id.is_valid()) {
|
||||
result.push_back(video_file_id);
|
||||
auto thumbnail_file_id =
|
||||
G()->td().get_actor_unsafe()->videos_manager_->get_video_thumbnail_file_id(video_file_id);
|
||||
if (thumbnail_file_id.is_valid()) {
|
||||
result.push_back(thumbnail_file_id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockVideo>(
|
||||
G()->td().get_actor_unsafe()->videos_manager_->get_video_object(video_file_id), get_rich_text_object(caption),
|
||||
@ -1044,6 +1079,10 @@ class WebPagesManager::PageBlockCover : public PageBlock {
|
||||
return Type::Cover;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
return cover->get_file_ids();
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockCover>(cover->get_page_block_object());
|
||||
}
|
||||
@ -1087,6 +1126,10 @@ class WebPagesManager::PageBlockEmbedded : public PageBlock {
|
||||
return Type::Embedded;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
return photo_get_file_ids(poster_photo);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockEmbedded>(
|
||||
url, html, get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &poster_photo), dimensions.width,
|
||||
@ -1148,6 +1191,14 @@ class WebPagesManager::PageBlockEmbeddedPost : public PageBlock {
|
||||
return Type::EmbeddedPost;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result = photo_get_file_ids(author_photo);
|
||||
for (auto &page_block : page_blocks) {
|
||||
append(result, page_block->get_file_ids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockEmbeddedPost>(
|
||||
url, author, get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &author_photo), date,
|
||||
@ -1190,6 +1241,14 @@ class WebPagesManager::PageBlockCollage : public PageBlock {
|
||||
return Type::Collage;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result;
|
||||
for (auto &page_block : page_blocks) {
|
||||
append(result, page_block->get_file_ids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockCollage>(get_page_block_objects(page_blocks), get_rich_text_object(caption));
|
||||
}
|
||||
@ -1223,6 +1282,14 @@ class WebPagesManager::PageBlockSlideshow : public PageBlock {
|
||||
return Type::Slideshow;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result;
|
||||
for (auto &page_block : page_blocks) {
|
||||
append(result, page_block->get_file_ids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockSlideshow>(get_page_block_objects(page_blocks),
|
||||
get_rich_text_object(caption));
|
||||
@ -1258,6 +1325,10 @@ class WebPagesManager::PageBlockChatLink : public PageBlock {
|
||||
return Type::ChatLink;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
return dialog_photo_get_file_ids(photo);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockChatLink>(
|
||||
title, get_chat_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &photo), username);
|
||||
@ -1293,6 +1364,19 @@ class WebPagesManager::PageBlockAudio : public PageBlock {
|
||||
return Type::Audio;
|
||||
}
|
||||
|
||||
vector<FileId> get_file_ids() const override {
|
||||
vector<FileId> result;
|
||||
if (audio_file_id.is_valid()) {
|
||||
result.push_back(audio_file_id);
|
||||
auto thumbnail_file_id =
|
||||
G()->td().get_actor_unsafe()->audios_manager_->get_audio_thumbnail_file_id(audio_file_id);
|
||||
if (thumbnail_file_id.is_valid()) {
|
||||
result.push_back(thumbnail_file_id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||
return make_tl_object<td_api::pageBlockAudio>(
|
||||
G()->td().get_actor_unsafe()->audios_manager_->get_audio_object(audio_file_id), get_rich_text_object(caption));
|
||||
@ -1805,7 +1889,7 @@ void WebPagesManager::load_web_page_instant_view(WebPageId web_page_id, bool for
|
||||
}
|
||||
LOG(INFO) << "Load " << web_page_id << " instant view, have " << previous_queries << " previous queries";
|
||||
if (previous_queries == 0) {
|
||||
const WebPageInstantView *web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
const auto *web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
CHECK(web_page_instant_view != nullptr);
|
||||
|
||||
if (G()->parameters().use_message_db && !web_page_instant_view->was_loaded_from_database) {
|
||||
@ -1841,7 +1925,7 @@ void WebPagesManager::on_load_web_page_instant_view_from_database(WebPageId web_
|
||||
// G()->td_db()->get_sqlite_pmc()->erase(get_web_page_instant_view_database_key(web_page_id), Auto());
|
||||
// return;
|
||||
|
||||
auto web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
auto *web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
if (web_page_instant_view == nullptr) {
|
||||
// possible if web page loses preview/instant view
|
||||
LOG(WARNING) << "There is no instant view in " << web_page_id;
|
||||
@ -1896,7 +1980,7 @@ void WebPagesManager::update_web_page_instant_view_load_requests(WebPageId web_p
|
||||
}
|
||||
LOG(INFO) << "Successfully loaded web page " << web_page_id;
|
||||
|
||||
auto web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
const auto *web_page_instant_view = get_web_page_instant_view(web_page_id);
|
||||
if (web_page_instant_view == nullptr) {
|
||||
combine(promises[0], std::move(promises[1]));
|
||||
for (auto &promise : promises[0]) {
|
||||
@ -2790,4 +2874,18 @@ string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const {
|
||||
return PSTRING() << web_page->title + " " + web_page->description;
|
||||
}
|
||||
|
||||
vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) {
|
||||
CHECK(web_page != nullptr);
|
||||
vector<FileId> result = photo_get_file_ids(web_page->photo);
|
||||
if (web_page->document_file_id.is_valid()) {
|
||||
result.push_back(web_page->document_file_id);
|
||||
}
|
||||
if (!web_page->instant_view.is_empty) {
|
||||
for (auto &page_block : web_page->instant_view.page_blocks) {
|
||||
append(result, page_block->get_file_ids());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -218,6 +218,8 @@ class WebPagesManager : public Actor {
|
||||
|
||||
void tear_down() override;
|
||||
|
||||
static vector<FileId> get_web_page_file_ids(const WebPage *web_page);
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
std::unordered_map<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_;
|
||||
|
Reference in New Issue
Block a user