summaryrefslogtreecommitdiffstats
path: root/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.h
blob: 7718f3c641deeba36be3ed44c65db45f70d4081a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.

For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once

#include <any>

class Image;
class HistoryItem;
enum class ImageRoundRadius;

namespace style {
struct DialogRow;
} // namespace style

namespace Ui {
} // namespace Ui

namespace Data {
class Forum;
} // namespace Data

namespace HistoryView {
struct ToPreviewOptions;
struct ItemPreviewImage;
struct ItemPreview;
} // namespace HistoryView

namespace Dialogs::Ui {

using namespace ::Ui;

struct PaintContext;
struct TopicJumpCache;
class TopicsView;

[[nodiscard]] TextWithEntities DialogsPreviewText(TextWithEntities text);

class MessageView final {
public:
	MessageView();
	~MessageView();

	using ToPreviewOptions = HistoryView::ToPreviewOptions;
	using ItemPreviewImage = HistoryView::ItemPreviewImage;
	using ItemPreview = HistoryView::ItemPreview;

	void itemInvalidated(not_null<const HistoryItem*> item);
	[[nodiscard]] bool dependsOn(not_null<const HistoryItem*> item) const;

	[[nodiscard]] bool prepared(
		not_null<const HistoryItem*> item,
		Data::Forum *forum) const;
	void prepare(
		not_null<const HistoryItem*> item,
		Data::Forum *forum,
		Fn<void()> customEmojiRepaint,
		ToPreviewOptions options);

	void paint(
		Painter &p,
		const QRect &geometry,
		const PaintContext &context) const;

	[[nodiscard]] bool isInTopicJump(int x, int y) const;
	void addTopicJumpRipple(
		QPoint origin,
		not_null<TopicJumpCache*> topicJumpCache,
		Fn<void()> updateCallback);
	void stopLastRipple();

private:
	struct LoadingContext;

	[[nodiscard]] int countWidth() const;
	void paintJumpToLast(
		Painter &p,
		const QRect &rect,
		const PaintContext &context,
		int width1) const;

	mutable const HistoryItem *_textCachedFor = nullptr;
	mutable Text::String _senderCache;
	mutable std::unique_ptr<TopicsView> _topics;
	mutable Text::String _textCache;
	mutable std::vector<ItemPreviewImage> _imagesCache;
	mutable std::unique_ptr<LoadingContext> _loadingContext;

};

[[nodiscard]] HistoryView::ItemPreview PreviewWithSender(
	HistoryView::ItemPreview &&preview,
	const QString &sender,
	TextWithEntities topic);

} // namespace Dialogs::Ui