File: data_thread.h

package info (click to toggle)
telegram-desktop 4.6.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 53,300 kB
  • sloc: cpp: 605,857; python: 3,978; ansic: 1,636; sh: 965; makefile: 841; objc: 652; javascript: 187; xml: 165
file content (141 lines) | stat: -rw-r--r-- 3,812 bytes parent folder | download | duplicates (3)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
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 "base/flags.h"
#include "dialogs/dialogs_entry.h"
#include "dialogs/ui/dialogs_message_view.h"
#include "ui/text/text.h"

#include <deque>

enum class ChatRestriction;
using ChatRestrictions = base::flags<ChatRestriction>;

namespace Main {
class Session;
} // namespace Main

namespace HistoryUnreadThings {
enum class AddType;
struct All;
class Proxy;
class ConstProxy;
} // namespace HistoryUnreadThings

namespace HistoryView {
class SendActionPainter;
} // namespace HistoryView

namespace st {
extern const int &dialogsTextWidthMin;
} // namespace st

namespace Data {

class PeerNotifySettings;

enum class ItemNotificationType {
	Message,
	Reaction,
};

struct ItemNotification {
	not_null<HistoryItem*> item;
	UserData *reactionSender = nullptr;
	ItemNotificationType type = ItemNotificationType::Message;

	friend inline auto operator<=>(
		ItemNotification a,
		ItemNotification b) = default;
};

class Thread : public Dialogs::Entry {
public:
	using Entry::Entry;
	~Thread();

	[[nodiscard]] virtual not_null<History*> owningHistory() = 0;

	[[nodiscard]] not_null<Thread*> migrateToOrMe() const;
	[[nodiscard]] not_null<const History*> owningHistory() const {
		return const_cast<Thread*>(this)->owningHistory();
	}
	[[nodiscard]] MsgId topicRootId() const;
	[[nodiscard]] not_null<PeerData*> peer() const;
	[[nodiscard]] PeerNotifySettings &notify();
	[[nodiscard]] const PeerNotifySettings &notify() const;

	void setUnreadThingsKnown();
	[[nodiscard]] HistoryUnreadThings::Proxy unreadMentions();
	[[nodiscard]] HistoryUnreadThings::ConstProxy unreadMentions() const;
	[[nodiscard]] HistoryUnreadThings::Proxy unreadReactions();
	[[nodiscard]] HistoryUnreadThings::ConstProxy unreadReactions() const;
	virtual void hasUnreadMentionChanged(bool has) = 0;
	virtual void hasUnreadReactionChanged(bool has) = 0;

	void removeNotification(not_null<HistoryItem*> item);
	void clearNotifications();
	void clearIncomingNotifications();
	[[nodiscard]] auto currentNotification() const
		-> std::optional<ItemNotification>;
	bool hasNotification() const;
	void skipNotification();
	void pushNotification(ItemNotification notification);
	void popNotification(ItemNotification notification);

	[[nodiscard]] bool muted() const {
		return (_flags & Flag::Muted);
	}
	virtual void setMuted(bool muted);

	[[nodiscard]] bool unreadMark() const {
		return (_flags & Flag::UnreadMark);
	}

	[[nodiscard]] virtual bool isServerSideUnread(
		not_null<const HistoryItem*> item) const = 0;

	[[nodiscard]] const base::flat_set<MsgId> &unreadMentionsIds() const;
	[[nodiscard]] const base::flat_set<MsgId> &unreadReactionsIds() const;

	[[nodiscard]] Ui::Text::String &cloudDraftTextCache() {
		return _cloudDraftTextCache;
	}
	[[nodiscard]] Dialogs::Ui::MessageView &lastItemDialogsView() {
		return _lastItemDialogsView;
	}

	[[nodiscard]] virtual auto sendActionPainter()
		-> not_null<HistoryView::SendActionPainter*> = 0;

	[[nodiscard]] bool hasPinnedMessages() const;
	void setHasPinnedMessages(bool has);

protected:
	void setUnreadMarkFlag(bool unread);

private:
	enum class Flag : uchar {
		UnreadMark = (1 << 0),
		Muted = (1 << 1),
		UnreadThingsKnown = (1 << 2),
		HasPinnedMessages = (1 << 3),
	};
	friend inline constexpr bool is_flag_type(Flag) { return true; }

	Ui::Text::String _cloudDraftTextCache = { st::dialogsTextWidthMin };
	Dialogs::Ui::MessageView _lastItemDialogsView;
	std::unique_ptr<HistoryUnreadThings::All> _unreadThings;
	std::deque<ItemNotification> _notifications;

	base::flags<Flag> _flags;

};

} // namespace Data