2019-04-27 02:57:59 +02:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2019-04-27 02:57:59 +02:00
|
|
|
//
|
|
|
|
// 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/files/FileId.h"
|
|
|
|
#include "td/telegram/logevent/LogEvent.h"
|
|
|
|
#include "td/telegram/Photo.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2020-03-02 22:40:52 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2020-03-02 20:31:01 +01:00
|
|
|
struct GetWebPageBlockObjectContext;
|
|
|
|
|
2019-04-27 02:57:59 +02:00
|
|
|
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,
|
2019-05-30 00:35:19 +02:00
|
|
|
Map,
|
2019-09-27 02:21:55 +02:00
|
|
|
VoiceNote,
|
2019-05-30 00:35:19 +02:00
|
|
|
Size
|
2019-04-27 02:57:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-03-02 20:31:01 +01:00
|
|
|
using Context = GetWebPageBlockObjectContext;
|
|
|
|
|
2019-04-27 02:57:59 +02:00
|
|
|
public:
|
|
|
|
WebPageBlock() = default;
|
|
|
|
WebPageBlock(const WebPageBlock &) = delete;
|
|
|
|
WebPageBlock &operator=(const WebPageBlock &) = delete;
|
|
|
|
WebPageBlock(WebPageBlock &&) = delete;
|
|
|
|
WebPageBlock &operator=(WebPageBlock &&) = delete;
|
|
|
|
virtual ~WebPageBlock() = default;
|
|
|
|
|
2020-03-02 20:31:01 +01:00
|
|
|
virtual void append_file_ids(const Td *td, vector<FileId> &file_ids) const = 0;
|
2019-04-27 02:57:59 +02:00
|
|
|
|
2020-03-02 20:31:01 +01:00
|
|
|
virtual td_api::object_ptr<td_api::PageBlock> get_page_block_object(Context *context) const = 0;
|
2019-04-27 02:57:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-09-27 02:21:55 +02:00
|
|
|
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, const std::unordered_map<int64, FileId> &voice_notes);
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
vector<td_api::object_ptr<td_api::PageBlock>> get_page_block_objects(
|
2020-03-02 22:40:52 +01:00
|
|
|
const vector<unique_ptr<WebPageBlock>> &page_blocks, Td *td, Slice base_url);
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
} // namespace td
|