/
data_user.h
245 lines (196 loc) · 6.67 KB
/
data_user.h
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
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_birthday.h"
#include "data/data_peer.h"
#include "data/data_chat_participant_status.h"
#include "data/data_lastseen_status.h"
#include "data/data_user_names.h"
#include "dialogs/dialogs_key.h"
namespace Data {
struct BotCommand;
struct BusinessDetails;
} // namespace Data
struct BotInfo {
BotInfo();
QString description;
QString inlinePlaceholder;
std::vector<Data::BotCommand> commands;
PhotoData *photo = nullptr;
DocumentData *document = nullptr;
QString botMenuButtonText;
QString botMenuButtonUrl;
QString startToken;
Dialogs::EntryState inlineReturnTo;
ChatAdminRights groupAdminRights;
ChatAdminRights channelAdminRights;
int version = 0;
int descriptionVersion = 0;
bool inited : 1 = false;
bool readsAllHistory : 1 = false;
bool cantJoinGroups : 1 = false;
bool supportsAttachMenu : 1 = false;
bool canEditInformation : 1 = false;
bool supportsBusiness : 1 = false;
};
enum class UserDataFlag : uint32 {
Contact = (1 << 0),
MutualContact = (1 << 1),
Deleted = (1 << 2),
Verified = (1 << 3),
Scam = (1 << 4),
Fake = (1 << 5),
BotInlineGeo = (1 << 6),
Blocked = (1 << 7),
HasPhoneCalls = (1 << 8),
PhoneCallsPrivate = (1 << 9),
Support = (1 << 10),
CanPinMessages = (1 << 11),
DiscardMinPhoto = (1 << 12),
Self = (1 << 13),
Premium = (1 << 14),
CanReceiveGifts = (1 << 15),
VoiceMessagesForbidden = (1 << 16),
PersonalPhoto = (1 << 17),
StoriesHidden = (1 << 18),
HasActiveStories = (1 << 19),
HasUnreadStories = (1 << 20),
MeRequiresPremiumToWrite = (1 << 21),
SomeRequirePremiumToWrite = (1 << 22),
RequirePremiumToWriteKnown = (1 << 23),
ReadDatesPrivate = (1 << 24),
};
inline constexpr bool is_flag_type(UserDataFlag) { return true; };
using UserDataFlags = base::flags<UserDataFlag>;
[[nodiscard]] Data::LastseenStatus LastseenFromMTP(
const MTPUserStatus &status,
Data::LastseenStatus currentStatus);
class UserData final : public PeerData {
public:
using Flag = UserDataFlag;
using Flags = Data::Flags<UserDataFlags>;
UserData(not_null<Data::Session*> owner, PeerId id);
~UserData();
void setPhoto(const MTPUserProfilePhoto &photo);
void setName(
const QString &newFirstName,
const QString &newLastName,
const QString &newPhoneName,
const QString &newUsername);
void setUsernames(const Data::Usernames &newUsernames);
void setUsername(const QString &username);
void setPhone(const QString &newPhone);
void setBotInfoVersion(int version);
void setBotInfo(const MTPBotInfo &info);
void setNameOrPhone(const QString &newNameOrPhone);
void madeAction(TimeId when); // pseudo-online
uint64 accessHash() const {
return _accessHash;
}
void setAccessHash(uint64 accessHash);
auto flags() const {
return _flags.current();
}
auto flagsValue() const {
return _flags.value();
}
void setFlags(UserDataFlags which);
void addFlags(UserDataFlags which);
void removeFlags(UserDataFlags which);
[[nodiscard]] bool isVerified() const;
[[nodiscard]] bool isScam() const;
[[nodiscard]] bool isFake() const;
[[nodiscard]] bool isPremium() const;
[[nodiscard]] bool isBotInlineGeo() const;
[[nodiscard]] bool isBot() const;
[[nodiscard]] bool isSupport() const;
[[nodiscard]] bool isInaccessible() const;
[[nodiscard]] bool applyMinPhoto() const;
[[nodiscard]] bool hasPersonalPhoto() const;
[[nodiscard]] bool hasStoriesHidden() const;
[[nodiscard]] bool someRequirePremiumToWrite() const;
[[nodiscard]] bool meRequiresPremiumToWrite() const;
[[nodiscard]] bool requirePremiumToWriteKnown() const;
[[nodiscard]] bool canSendIgnoreRequirePremium() const;
[[nodiscard]] bool readDatesPrivate() const;
[[nodiscard]] bool canShareThisContact() const;
[[nodiscard]] bool canAddContact() const;
[[nodiscard]] bool canReceiveGifts() const;
// In Data::Session::processUsers() we check only that.
// When actually trying to share contact we perform
// a full check by canShareThisContact() call.
[[nodiscard]] bool canShareThisContactFast() const;
[[nodiscard]] const QString &phone() const;
[[nodiscard]] QString username() const;
[[nodiscard]] QString editableUsername() const;
[[nodiscard]] const std::vector<QString> &usernames() const;
[[nodiscard]] bool isUsernameEditable(QString username) const;
enum class ContactStatus : char {
Unknown,
Contact,
NotContact,
};
[[nodiscard]] ContactStatus contactStatus() const;
[[nodiscard]] bool isContact() const;
void setIsContact(bool is);
[[nodiscard]] Data::LastseenStatus lastseen() const;
bool updateLastseen(Data::LastseenStatus value);
enum class CallsStatus : char {
Unknown,
Enabled,
Disabled,
Private,
};
CallsStatus callsStatus() const;
bool hasCalls() const;
void setCallsStatus(CallsStatus callsStatus);
[[nodiscard]] Data::Birthday birthday() const;
void setBirthday(Data::Birthday value);
void setBirthday(const tl::conditional<MTPBirthday> &value);
void setUnavailableReasons(
std::vector<Data::UnavailableReason> &&reasons);
int commonChatsCount() const;
void setCommonChatsCount(int count);
[[nodiscard]] bool hasPrivateForwardName() const;
[[nodiscard]] QString privateForwardName() const;
void setPrivateForwardName(const QString &name);
[[nodiscard]] bool hasActiveStories() const;
[[nodiscard]] bool hasUnreadStories() const;
void setStoriesState(StoriesState state);
[[nodiscard]] const Data::BusinessDetails &businessDetails() const;
void setBusinessDetails(Data::BusinessDetails details);
[[nodiscard]] ChannelId personalChannelId() const;
[[nodiscard]] MsgId personalChannelMessageId() const;
void setPersonalChannel(ChannelId channelId, MsgId messageId);
MTPInputUser inputUser = MTP_inputUserEmpty();
QString firstName;
QString lastName;
QString nameOrPhone;
std::unique_ptr<BotInfo> botInfo;
private:
auto unavailableReasons() const
-> const std::vector<Data::UnavailableReason> & override;
Flags _flags;
Data::LastseenStatus _lastseen;
Data::Birthday _birthday;
int _commonChatsCount = 0;
ContactStatus _contactStatus = ContactStatus::Unknown;
CallsStatus _callsStatus = CallsStatus::Unknown;
Data::UsernamesInfo _username;
std::unique_ptr<Data::BusinessDetails> _businessDetails;
std::vector<Data::UnavailableReason> _unavailableReasons;
QString _phone;
QString _privateForwardName;
ChannelId _personalChannelId = 0;
MsgId _personalChannelMessageId = 0;
uint64 _accessHash = 0;
static constexpr auto kInaccessibleAccessHashOld
= 0xFFFFFFFFFFFFFFFFULL;
};
namespace Data {
void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update);
} // namespace Data