2019-04-27 02:57:59 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
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"
|
2022-02-07 20:41:07 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
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;
|
2024-08-07 10:47:37 +02:00
|
|
|
|
|
|
|
static bool are_allowed_album_block_types(const vector<unique_ptr<WebPageBlock>> &page_blocks);
|
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,
|
2022-02-07 20:41:07 +01:00
|
|
|
const FlatHashMap<int64, FileId> &animations, const FlatHashMap<int64, FileId> &audios,
|
2022-02-11 17:27:32 +01:00
|
|
|
const FlatHashMap<int64, FileId> &documents, const FlatHashMap<int64, unique_ptr<Photo>> &photos,
|
2022-02-07 20:41:07 +01:00
|
|
|
const FlatHashMap<int64, FileId> &videos, const FlatHashMap<int64, FileId> &voice_notes);
|
2019-04-27 02:57:59 +02:00
|
|
|
|
2022-08-30 07:12:14 +02:00
|
|
|
vector<td_api::object_ptr<td_api::PageBlock>> get_page_blocks_object(
|
2022-09-26 18:24:39 +02:00
|
|
|
const vector<unique_ptr<WebPageBlock>> &page_blocks, Td *td, Slice base_url, Slice real_url);
|
2019-04-27 02:57:59 +02:00
|
|
|
|
|
|
|
} // namespace td
|