1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "data/data_photo.h"
11 #include "data/data_document.h"
12 
13 class ChannelData;
14 
15 namespace Data {
16 class Session;
17 } // namespace Data
18 
19 enum class WebPageType {
20 	Message,
21 
22 	Group,
23 	GroupWithRequest,
24 	Channel,
25 	ChannelWithRequest,
26 
27 	Photo,
28 	Video,
29 
30 	User,
31 	Bot,
32 	Profile,
33 
34 	WallPaper,
35 	Theme,
36 
37 	Article,
38 	ArticleWithIV,
39 
40 	VoiceChat,
41 	Livestream,
42 };
43 
44 WebPageType ParseWebPageType(const MTPDwebPage &type);
45 
46 struct WebPageCollage {
47 	using Item = std::variant<PhotoData*, DocumentData*>;
48 
49 	WebPageCollage() = default;
50 	explicit WebPageCollage(
51 		not_null<Data::Session*> owner,
52 		const MTPDwebPage &data);
53 
54 	std::vector<Item> items;
55 
56 };
57 
58 struct WebPageData {
59 	WebPageData(not_null<Data::Session*> owner, const WebPageId &id);
60 
61 	[[nodiscard]] Data::Session &owner() const;
62 	[[nodiscard]] Main::Session &session() const;
63 
64 	bool applyChanges(
65 		WebPageType newType,
66 		const QString &newUrl,
67 		const QString &newDisplayUrl,
68 		const QString &newSiteName,
69 		const QString &newTitle,
70 		const TextWithEntities &newDescription,
71 		PhotoData *newPhoto,
72 		DocumentData *newDocument,
73 		WebPageCollage &&newCollage,
74 		int newDuration,
75 		const QString &newAuthor,
76 		int newPendingTill);
77 
78 	static void ApplyChanges(
79 		not_null<Main::Session*> session,
80 		ChannelData *channel,
81 		const MTPmessages_Messages &result);
82 
83 	WebPageId id = 0;
84 	WebPageType type = WebPageType::Article;
85 	QString url;
86 	QString displayUrl;
87 	QString siteName;
88 	QString title;
89 	TextWithEntities description;
90 	int duration = 0;
91 	QString author;
92 	PhotoData *photo = nullptr;
93 	DocumentData *document = nullptr;
94 	WebPageCollage collage;
95 	int pendingTill = 0;
96 	int version = 0;
97 
98 private:
99 	void replaceDocumentGoodThumbnail();
100 
101 	const not_null<Data::Session*> _owner;
102 
103 };
104