File: data_peer_values.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 (180 lines) | stat: -rw-r--r-- 5,525 bytes parent folder | download
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
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 "data/data_peer.h"
#include "data/data_chat_participant_status.h"

enum class ImageRoundRadius;

namespace Main {
class Session;
} // namespace Main

namespace Data {

struct Reaction;
class ForumTopic;

template <typename ChangeType, typename Error, typename Generator>
inline auto FlagsValueWithMask(
		rpl::producer<ChangeType, Error, Generator> &&value,
		typename ChangeType::Type mask) {
	return std::move(
		value
	) | rpl::filter([mask](const ChangeType &change) {
		return change.diff & mask;
	}) | rpl::map([mask](const ChangeType &change) {
		return change.value & mask;
	});
}

template <typename ChangeType, typename Error, typename Generator>
inline auto SingleFlagValue(
		rpl::producer<ChangeType, Error, Generator> &&value,
		typename ChangeType::Enum flag) {
	return FlagsValueWithMask(
		std::move(value),
		flag
	) | rpl::map([](typename ChangeType::Type value) {
		return !!value;
	});
}

template <
	typename PeerType,
	typename ChangeType = typename PeerType::Flags::Change>
inline auto PeerFlagsValue(PeerType *peer) {
	Expects(peer != nullptr);

	return peer->flagsValue();
}

template <
	typename PeerType,
	typename ChangeType = typename PeerType::Flags::Change>
inline auto PeerFlagsValue(
		PeerType *peer,
		typename PeerType::Flags::Type mask) {
	return FlagsValueWithMask(PeerFlagsValue(peer), mask);
}

template <
	typename PeerType,
	typename ChangeType = typename PeerType::Flags::Change>
inline auto PeerFlagValue(
		PeerType *peer,
		typename PeerType::Flags::Enum flag) {
	return SingleFlagValue(PeerFlagsValue(peer), flag);
}

template <
	typename PeerType,
	typename = typename PeerType::FullFlags::Change>
inline auto PeerFullFlagsValue(PeerType *peer) {
	Expects(peer != nullptr);

	return peer->fullFlagsValue();
}

template <
	typename PeerType,
	typename = typename PeerType::FullFlags::Change>
inline auto PeerFullFlagsValue(
		PeerType *peer,
		typename PeerType::FullFlags::Type mask) {
	return FlagsValueWithMask(PeerFullFlagsValue(peer), mask);
}

template <
	typename PeerType,
	typename = typename PeerType::FullFlags::Change>
inline auto PeerFullFlagValue(
		PeerType *peer,
		typename PeerType::FullFlags::Enum flag) {
	return SingleFlagValue(PeerFullFlagsValue(peer), flag);
}

[[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
	not_null<Data::Thread*> thread,
	ChatRestrictions rights,
	bool forbidInForums = true);
[[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
	not_null<PeerData*> peer,
	ChatRestrictions rights,
	bool forbidInForums = true);

[[nodiscard]] inline rpl::producer<bool> CanSendValue(
		not_null<Thread*> thread,
		ChatRestriction right,
		bool forbidInForums = true) {
	return CanSendAnyOfValue(thread, right, forbidInForums);
}
[[nodiscard]] inline rpl::producer<bool> CanSendValue(
		not_null<PeerData*> peer,
		ChatRestriction right,
		bool forbidInForums = true) {
	return CanSendAnyOfValue(peer, right, forbidInForums);
}
[[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
		not_null<Thread*> thread,
		bool forbidInForums = true) {
	return CanSendValue(thread, ChatRestriction::SendOther, forbidInForums);
}
[[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
		not_null<PeerData*> peer,
		bool forbidInForums = true) {
	return CanSendValue(peer, ChatRestriction::SendOther, forbidInForums);
}
[[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
		not_null<Thread*> thread,
		bool forbidInForums = true) {
	return CanSendAnyOfValue(thread, AllSendRestrictions(), forbidInForums);
}
[[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
		not_null<PeerData*> peer,
		bool forbidInForums = true) {
	return CanSendAnyOfValue(peer, AllSendRestrictions(), forbidInForums);
}

[[nodiscard]] rpl::producer<bool> CanPinMessagesValue(
	not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<bool> CanManageGroupCallValue(
	not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<bool> PeerPremiumValue(not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<bool> AmPremiumValue(
	not_null<Main::Session*> session);

[[nodiscard]] TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now);
[[nodiscard]] crl::time OnlineChangeTimeout(TimeId online, TimeId now);
[[nodiscard]] crl::time OnlineChangeTimeout(
	not_null<UserData*> user,
	TimeId now);
[[nodiscard]] QString OnlineText(TimeId online, TimeId now);
[[nodiscard]] QString OnlineText(not_null<UserData*> user, TimeId now);
[[nodiscard]] QString OnlineTextFull(not_null<UserData*> user, TimeId now);
[[nodiscard]] bool OnlineTextActive(TimeId online, TimeId now);
[[nodiscard]] bool OnlineTextActive(not_null<UserData*> user, TimeId now);
[[nodiscard]] bool IsUserOnline(not_null<UserData*> user, TimeId now = 0);
[[nodiscard]] bool ChannelHasActiveCall(not_null<ChannelData*> channel);

[[nodiscard]] rpl::producer<QImage> PeerUserpicImageValue(
	not_null<PeerData*> peer,
	int size,
	std::optional<int> radius = {});

[[nodiscard]] const AllowedReactions &PeerAllowedReactions(
	not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<AllowedReactions> PeerAllowedReactionsValue(
	not_null<PeerData*> peer);

[[nodiscard]] int UniqueReactionsLimit(not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<int> UniqueReactionsLimitValue(
	not_null<PeerData*> peer);

} // namespace Data