Add get_web_page_file_ids method.

GitOrigin-RevId: f25119ed147005068f9ff709813ba10e8810fc57
This commit is contained in:
levlam 2019-01-22 00:59:55 +03:00
parent 73d09e1816
commit e8d3674eb4
2 changed files with 103 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
#include "td/telegram/DocumentsManager.hpp" #include "td/telegram/DocumentsManager.hpp"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileManager.hpp" #include "td/telegram/files/FileManager.hpp"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
@ -449,6 +450,10 @@ class WebPagesManager::PageBlock {
virtual Type get_type() const = 0; 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; virtual tl_object_ptr<td_api::PageBlock> get_page_block_object() const = 0;
PageBlock() = default; PageBlock() = default;
@ -888,6 +893,19 @@ class WebPagesManager::PageBlockAnimation : public PageBlock {
return Type::Animation; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockAnimation>( return make_tl_object<td_api::pageBlockAnimation>(
G()->td().get_actor_unsafe()->animations_manager_->get_animation_object(animation_file_id, 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; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockPhoto>( return make_tl_object<td_api::pageBlockPhoto>(
get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &photo), get_rich_text_object(caption)); 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; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockVideo>( 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), 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; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockCover>(cover->get_page_block_object()); return make_tl_object<td_api::pageBlockCover>(cover->get_page_block_object());
} }
@ -1087,6 +1126,10 @@ class WebPagesManager::PageBlockEmbedded : public PageBlock {
return Type::Embedded; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockEmbedded>( return make_tl_object<td_api::pageBlockEmbedded>(
url, html, get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &poster_photo), dimensions.width, 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; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockEmbeddedPost>( return make_tl_object<td_api::pageBlockEmbeddedPost>(
url, author, get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &author_photo), date, 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; 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 { 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)); 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; 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 { 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), return make_tl_object<td_api::pageBlockSlideshow>(get_page_block_objects(page_blocks),
get_rich_text_object(caption)); get_rich_text_object(caption));
@ -1258,6 +1325,10 @@ class WebPagesManager::PageBlockChatLink : public PageBlock {
return Type::ChatLink; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockChatLink>( return make_tl_object<td_api::pageBlockChatLink>(
title, get_chat_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &photo), username); 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; 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 { tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
return make_tl_object<td_api::pageBlockAudio>( 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)); 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"; LOG(INFO) << "Load " << web_page_id << " instant view, have " << previous_queries << " previous queries";
if (previous_queries == 0) { 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); CHECK(web_page_instant_view != nullptr);
if (G()->parameters().use_message_db && !web_page_instant_view->was_loaded_from_database) { 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()); // G()->td_db()->get_sqlite_pmc()->erase(get_web_page_instant_view_database_key(web_page_id), Auto());
// return; // 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) { if (web_page_instant_view == nullptr) {
// possible if web page loses preview/instant view // possible if web page loses preview/instant view
LOG(WARNING) << "There is no instant view in " << web_page_id; 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; 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) { if (web_page_instant_view == nullptr) {
combine(promises[0], std::move(promises[1])); combine(promises[0], std::move(promises[1]));
for (auto &promise : promises[0]) { 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; 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 } // namespace td

View File

@ -218,6 +218,8 @@ class WebPagesManager : public Actor {
void tear_down() override; void tear_down() override;
static vector<FileId> get_web_page_file_ids(const WebPage *web_page);
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;
std::unordered_map<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_; std::unordered_map<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_;