2019-01-04 11:09:48 +00:00
|
|
|
/*
|
|
|
|
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"
|
2022-03-23 10:15:52 +00:00
|
|
|
#include "data/data_chat_participant_status.h"
|
2020-11-12 15:46:17 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2022-05-14 20:50:02 +00:00
|
|
|
namespace Data {
|
|
|
|
struct BotCommand;
|
|
|
|
} // namespace Data
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
struct BotInfo {
|
2022-09-30 07:25:02 +00:00
|
|
|
BotInfo();
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool inited = false;
|
|
|
|
bool readsAllHistory = false;
|
|
|
|
bool cantJoinGroups = false;
|
2022-03-24 13:41:59 +00:00
|
|
|
bool supportsAttachMenu = false;
|
2019-01-04 11:09:48 +00:00
|
|
|
int version = 0;
|
|
|
|
QString description, inlinePlaceholder;
|
2022-05-14 20:50:02 +00:00
|
|
|
std::vector<Data::BotCommand> commands;
|
2022-09-30 07:25:02 +00:00
|
|
|
Ui::Text::String text;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2022-04-06 12:27:23 +00:00
|
|
|
QString botMenuButtonText;
|
|
|
|
QString botMenuButtonUrl;
|
|
|
|
|
2022-03-24 09:46:44 +00:00
|
|
|
QString startToken;
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState inlineReturnTo;
|
2022-03-23 10:15:52 +00:00
|
|
|
|
|
|
|
ChatAdminRights groupAdminRights;
|
|
|
|
ChatAdminRights channelAdminRights;
|
2019-01-04 11:09:48 +00:00
|
|
|
};
|
|
|
|
|
2021-07-08 11:19:12 +00:00
|
|
|
enum class UserDataFlag {
|
|
|
|
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),
|
2021-09-09 13:59:36 +00:00
|
|
|
DiscardMinPhoto = (1 << 12),
|
2021-12-01 14:51:18 +00:00
|
|
|
Self = (1 << 13),
|
2022-04-21 11:06:50 +00:00
|
|
|
Premium = (1 << 14),
|
2022-07-03 14:56:12 +00:00
|
|
|
CanReceiveGifts = (1 << 15),
|
2022-07-31 06:46:33 +00:00
|
|
|
VoiceMessagesForbidden = (1 << 16),
|
2021-07-08 11:19:12 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(UserDataFlag) { return true; };
|
|
|
|
using UserDataFlags = base::flags<UserDataFlag>;
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
class UserData final : public PeerData {
|
2019-01-04 11:09:48 +00:00
|
|
|
public:
|
2021-07-08 11:19:12 +00:00
|
|
|
using Flag = UserDataFlag;
|
|
|
|
using Flags = Data::Flags<UserDataFlags>;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
UserData(not_null<Data::Session*> owner, PeerId id);
|
|
|
|
void setPhoto(const MTPUserProfilePhoto &photo);
|
2022-08-19 12:38:11 +00:00
|
|
|
void setEmojiStatus(const MTPEmojiStatus &status);
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
void setName(
|
|
|
|
const QString &newFirstName,
|
|
|
|
const QString &newLastName,
|
|
|
|
const QString &newPhoneName,
|
|
|
|
const QString &newUsername);
|
|
|
|
|
2022-09-01 05:58:04 +00:00
|
|
|
void setEmojiStatus(DocumentId emojiStatusId, TimeId until = 0);
|
2022-08-09 15:53:40 +00:00
|
|
|
[[nodiscard]] DocumentId emojiStatusId() const;
|
|
|
|
|
2022-10-05 11:32:16 +00:00
|
|
|
void setUsername(const QString &username);
|
2019-01-04 11:09:48 +00:00
|
|
|
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();
|
|
|
|
}
|
2021-12-01 14:51:18 +00:00
|
|
|
void setFlags(UserDataFlags which);
|
|
|
|
void addFlags(UserDataFlags which);
|
|
|
|
void removeFlags(UserDataFlags which);
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
[[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 canWrite() const;
|
|
|
|
[[nodiscard]] bool applyMinPhoto() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool canShareThisContact() const;
|
2022-05-16 11:38:35 +00:00
|
|
|
[[nodiscard]] bool canAddContact() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2022-07-03 14:56:12 +00:00
|
|
|
[[nodiscard]] bool canReceiveGifts() const;
|
2022-07-14 19:25:04 +00:00
|
|
|
[[nodiscard]] bool canReceiveVoices() const;
|
2022-07-03 14:56:12 +00:00
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
// In Data::Session::processUsers() we check only that.
|
2019-01-04 11:09:48 +00:00
|
|
|
// When actually trying to share contact we perform
|
|
|
|
// a full check by canShareThisContact() call.
|
2022-05-16 11:38:35 +00:00
|
|
|
[[nodiscard]] bool canShareThisContactFast() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2020-09-17 15:13:12 +00:00
|
|
|
MTPInputUser inputUser = MTP_inputUserEmpty();
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
QString firstName;
|
|
|
|
QString lastName;
|
2022-05-16 11:38:35 +00:00
|
|
|
[[nodiscard]] const QString &phone() const;
|
2022-10-05 11:32:16 +00:00
|
|
|
[[nodiscard]] const QString &username() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
QString nameOrPhone;
|
|
|
|
TimeId onlineTill = 0;
|
|
|
|
|
2019-06-07 11:32:58 +00:00
|
|
|
enum class ContactStatus : char {
|
|
|
|
Unknown,
|
|
|
|
Contact,
|
|
|
|
NotContact,
|
|
|
|
};
|
2022-05-16 11:38:35 +00:00
|
|
|
[[nodiscard]] ContactStatus contactStatus() const;
|
|
|
|
[[nodiscard]] bool isContact() const;
|
2019-06-06 16:48:42 +00:00
|
|
|
void setIsContact(bool is);
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
enum class CallsStatus : char {
|
|
|
|
Unknown,
|
|
|
|
Enabled,
|
|
|
|
Disabled,
|
|
|
|
Private,
|
|
|
|
};
|
2022-05-16 11:38:35 +00:00
|
|
|
CallsStatus callsStatus() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
bool hasCalls() const;
|
|
|
|
void setCallsStatus(CallsStatus callsStatus);
|
|
|
|
|
|
|
|
std::unique_ptr<BotInfo> botInfo;
|
|
|
|
|
2019-12-09 13:57:33 +00:00
|
|
|
void setUnavailableReasons(
|
|
|
|
std::vector<Data::UnavailableReason> &&reasons);
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
int commonChatsCount() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
void setCommonChatsCount(int count);
|
|
|
|
|
|
|
|
private:
|
2019-12-09 13:57:33 +00:00
|
|
|
auto unavailableReasons() const
|
|
|
|
-> const std::vector<Data::UnavailableReason> & override;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
Flags _flags;
|
|
|
|
|
2019-12-09 13:57:33 +00:00
|
|
|
std::vector<Data::UnavailableReason> _unavailableReasons;
|
2022-10-05 11:32:16 +00:00
|
|
|
QString _username;
|
2019-01-04 11:09:48 +00:00
|
|
|
QString _phone;
|
2019-06-07 11:32:58 +00:00
|
|
|
ContactStatus _contactStatus = ContactStatus::Unknown;
|
2019-01-04 11:09:48 +00:00
|
|
|
CallsStatus _callsStatus = CallsStatus::Unknown;
|
|
|
|
int _commonChatsCount = 0;
|
|
|
|
|
|
|
|
uint64 _accessHash = 0;
|
|
|
|
static constexpr auto kInaccessibleAccessHashOld
|
|
|
|
= 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
|
2022-08-09 15:53:40 +00:00
|
|
|
DocumentId _emojiStatusId = 0;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
};
|
2019-04-23 09:40:14 +00:00
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update);
|
|
|
|
|
|
|
|
} // namespace Data
|