Refactor WebPagesManager::PageBlock to a separate class.

GitOrigin-RevId: 7a705f0929c1b4419d2cf0693dda747a172dbc28
This commit is contained in:
levlam 2019-04-27 03:57:59 +03:00
parent e7427ea57e
commit 740880b9ca
5 changed files with 2394 additions and 2366 deletions

View File

@ -446,6 +446,7 @@ set(TDLIB_SOURCE
td/telegram/VideosManager.cpp
td/telegram/VoiceNotesManager.cpp
td/telegram/WallpaperManager.cpp
td/telegram/WebPageBlock.cpp
td/telegram/WebPagesManager.cpp
td/mtproto/AuthData.h
@ -611,6 +612,7 @@ set(TDLIB_SOURCE
td/telegram/VideosManager.h
td/telegram/VoiceNotesManager.h
td/telegram/WallpaperManager.h
td/telegram/WebPageBlock.h
td/telegram/WebPageId.h
td/telegram/WebPagesManager.h

2283
td/telegram/WebPageBlock.cpp Normal file

File diff suppressed because it is too large Load Diff

104
td/telegram/WebPageBlock.h Normal file
View File

@ -0,0 +1,104 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/Photo.h"
#include "td/utils/common.h"
#include <unordered_map>
namespace td {
class Td;
class WebPageBlock {
protected:
enum class Type : int32 {
Title,
Subtitle,
AuthorDate,
Header,
Subheader,
Paragraph,
Preformatted,
Footer,
Divider,
Anchor,
List,
BlockQuote,
PullQuote,
Animation,
Photo,
Video,
Cover,
Embedded,
EmbeddedPost,
Collage,
Slideshow,
ChatLink,
Audio,
Kicker,
Table,
Details,
RelatedArticles,
Map
};
virtual Type get_type() const = 0;
template <class F>
static void call_impl(Type type, const WebPageBlock *ptr, F &&f);
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
static unique_ptr<WebPageBlock> parse(ParserT &parser);
template <class StorerT>
friend void store_web_page_block(const unique_ptr<WebPageBlock> &block, StorerT &storer);
template <class ParserT>
friend void parse_web_page_block(unique_ptr<WebPageBlock> &block, ParserT &parser);
public:
WebPageBlock() = default;
WebPageBlock(const WebPageBlock &) = delete;
WebPageBlock &operator=(const WebPageBlock &) = delete;
WebPageBlock(WebPageBlock &&) = delete;
WebPageBlock &operator=(WebPageBlock &&) = delete;
virtual ~WebPageBlock() = default;
virtual void append_file_ids(vector<FileId> &file_ids) const = 0;
virtual td_api::object_ptr<td_api::PageBlock> get_page_block_object() const = 0;
};
void store(const unique_ptr<WebPageBlock> &block, LogEventStorerCalcLength &storer);
void store(const unique_ptr<WebPageBlock> &block, LogEventStorerUnsafe &storer);
void parse(unique_ptr<WebPageBlock> &block, LogEventParser &parser);
vector<unique_ptr<WebPageBlock>> get_web_page_blocks(Td *td,
vector<tl_object_ptr<telegram_api::PageBlock>> page_block_ptrs,
const std::unordered_map<int64, FileId> &animations,
const std::unordered_map<int64, FileId> &audios,
const std::unordered_map<int64, FileId> &documents,
const std::unordered_map<int64, Photo> &photos,
const std::unordered_map<int64, FileId> &videos);
vector<td_api::object_ptr<td_api::PageBlock>> get_page_block_objects(
const vector<unique_ptr<WebPageBlock>> &page_blocks);
} // namespace td

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,8 @@ struct BinlogEvent;
class Td;
class WebPageBlock;
class WebPagesManager : public Actor {
public:
WebPagesManager(Td *td, ActorShared<> parent);
@ -98,52 +100,10 @@ class WebPagesManager : public Actor {
class WebPage;
class RichText;
class PageBlockCaption;
class PageBlockTableCell;
class RelatedArticle;
class PageBlock;
class PageBlockTitle;
class PageBlockSubtitle;
class PageBlockAuthorDate;
class PageBlockHeader;
class PageBlockSubheader;
class PageBlockKicker;
class PageBlockParagraph;
class PageBlockPreformatted;
class PageBlockFooter;
class PageBlockDivider;
class PageBlockAnchor;
class PageBlockList;
class PageBlockBlockQuote;
class PageBlockPullQuote;
class PageBlockAnimation;
class PageBlockPhoto;
class PageBlockVideo;
class PageBlockCover;
class PageBlockEmbedded;
class PageBlockEmbeddedPost;
class PageBlockCollage;
class PageBlockSlideshow;
class PageBlockChatLink;
class PageBlockAudio;
class PageBlockTable;
class PageBlockDetails;
class PageBlockRelatedArticles;
class PageBlockMap;
class WebPageInstantView;
class WebPageLogEvent;
template <class StorerT>
friend void store(const unique_ptr<PageBlock> &block, StorerT &storer);
template <class ParserT>
friend void parse(unique_ptr<PageBlock> &block, ParserT &parser);
void update_web_page(unique_ptr<WebPage> web_page, WebPageId web_page_id, bool from_binlog, bool from_database);
void update_web_page_instant_view(WebPageId web_page_id, WebPageInstantView &new_instant_view,
@ -169,41 +129,6 @@ class WebPagesManager : public Actor {
void on_get_web_page_preview_success(int64 request_id, const string &url, WebPageId web_page_id,
Promise<Unit> &&promise);
static RichText get_rich_text(tl_object_ptr<telegram_api::RichText> &&rich_text_ptr,
const std::unordered_map<int64, FileId> &documents);
static vector<RichText> get_rich_texts(vector<tl_object_ptr<telegram_api::RichText>> &&rich_text_ptrs,
const std::unordered_map<int64, FileId> &documents);
static tl_object_ptr<td_api::RichText> get_rich_text_object(const RichText &rich_text);
static vector<tl_object_ptr<td_api::RichText>> get_rich_text_objects(const vector<RichText> &rich_texts);
static PageBlockCaption get_page_block_caption(tl_object_ptr<telegram_api::pageCaption> &&page_caption,
const std::unordered_map<int64, FileId> &documents);
static td_api::object_ptr<td_api::pageBlockCaption> get_page_block_caption_object(const PageBlockCaption &caption);
static td_api::object_ptr<td_api::pageBlockTableCell> get_page_block_table_cell_object(
const PageBlockTableCell &cell);
static vector<tl_object_ptr<td_api::PageBlock>> get_page_block_objects(
const vector<unique_ptr<PageBlock>> &page_blocks);
unique_ptr<PageBlock> get_page_block(tl_object_ptr<telegram_api::PageBlock> page_block_ptr,
const std::unordered_map<int64, FileId> &animations,
const std::unordered_map<int64, FileId> &audios,
const std::unordered_map<int64, FileId> &documents,
const std::unordered_map<int64, Photo> &photos,
const std::unordered_map<int64, FileId> &videos) const;
vector<unique_ptr<PageBlock>> get_page_blocks(vector<tl_object_ptr<telegram_api::PageBlock>> page_block_ptrs,
const std::unordered_map<int64, FileId> &animations,
const std::unordered_map<int64, FileId> &audios,
const std::unordered_map<int64, FileId> &documents,
const std::unordered_map<int64, Photo> &photos,
const std::unordered_map<int64, FileId> &videos) const;
void on_get_web_page_instant_view(WebPage *web_page, tl_object_ptr<telegram_api::page> &&page, int32 hash,
DialogId owner_dialog_id);
@ -242,10 +167,6 @@ class WebPagesManager : public Actor {
FileSourceId get_web_page_file_source_id(WebPage *web_page);
static void append_rich_text_file_ids(const RichText &rich_text, vector<FileId> &file_ids);
static void append_page_block_caption_file_ids(const PageBlockCaption &caption, vector<FileId> &file_ids);
vector<FileId> get_web_page_file_ids(const WebPage *web_page) const;
Td *td_;