tdesktop/Telegram/SourceFiles/data/data_user.h

200 lines
5.0 KiB
C
Raw Normal View History

/*
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"
#include "data/data_user_names.h"
#include "dialogs/dialogs_key.h"
namespace Data {
struct BotCommand;
} // namespace Data
struct BotInfo {
BotInfo();
bool inited = false;
bool readsAllHistory = false;
bool cantJoinGroups = false;
bool supportsAttachMenu = false;
bool canEditInformation = false;
int version = 0;
int descriptionVersion = 0;
QString description;
QString inlinePlaceholder;
std::vector<Data::BotCommand> commands;
PhotoData *photo = nullptr;
DocumentData *document = nullptr;
2022-04-06 12:27:23 +00:00
QString botMenuButtonText;
QString botMenuButtonUrl;
QString startToken;
Dialogs::EntryState inlineReturnTo;
ChatAdminRights groupAdminRights;
ChatAdminRights channelAdminRights;
};
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),
DiscardMinPhoto = (1 << 12),
2021-12-01 14:51:18 +00:00
Self = (1 << 13),
Premium = (1 << 14),
2022-07-03 14:56:12 +00:00
CanReceiveGifts = (1 << 15),
VoiceMessagesForbidden = (1 << 16),
PersonalPhoto = (1 << 17),
2023-06-02 09:20:27 +00:00
StoriesHidden = (1 << 18),
2021-07-08 11:19:12 +00:00
};
inline constexpr bool is_flag_type(UserDataFlag) { return true; };
using UserDataFlags = base::flags<UserDataFlag>;
class UserData final : public PeerData {
public:
2021-07-08 11:19:12 +00:00
using Flag = UserDataFlag;
using Flags = Data::Flags<UserDataFlags>;
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);
void setName(
const QString &newFirstName,
const QString &newLastName,
const QString &newPhoneName,
const QString &newUsername);
void setUsernames(const Data::Usernames &newUsernames);
2022-09-01 05:58:04 +00:00
void setEmojiStatus(DocumentId emojiStatusId, TimeId until = 0);
[[nodiscard]] DocumentId emojiStatusId() const;
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();
}
2021-12-01 14:51:18 +00:00
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;
2023-06-02 09:20:27 +00:00
[[nodiscard]] bool hasStoriesHidden() const;
2021-01-21 12:39:40 +00:00
[[nodiscard]] bool canShareThisContact() const;
[[nodiscard]] bool canAddContact() const;
2022-07-03 14:56:12 +00:00
[[nodiscard]] bool canReceiveGifts() const;
2019-01-18 12:27:37 +00:00
// 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;
MTPInputUser inputUser = MTP_inputUserEmpty();
QString firstName;
QString lastName;
[[nodiscard]] const QString &phone() const;
[[nodiscard]] QString username() const;
[[nodiscard]] QString editableUsername() const;
2022-10-09 11:25:47 +00:00
[[nodiscard]] const std::vector<QString> &usernames() const;
QString nameOrPhone;
TimeId onlineTill = 0;
enum class ContactStatus : char {
Unknown,
Contact,
NotContact,
};
[[nodiscard]] ContactStatus contactStatus() const;
[[nodiscard]] bool isContact() const;
void setIsContact(bool is);
enum class CallsStatus : char {
Unknown,
Enabled,
Disabled,
Private,
};
CallsStatus callsStatus() const;
bool hasCalls() const;
void setCallsStatus(CallsStatus callsStatus);
std::unique_ptr<BotInfo> botInfo;
void setUnavailableReasons(
std::vector<Data::UnavailableReason> &&reasons);
int commonChatsCount() const;
void setCommonChatsCount(int count);
private:
auto unavailableReasons() const
-> const std::vector<Data::UnavailableReason> & override;
Flags _flags;
Data::UsernamesInfo _username;
std::vector<Data::UnavailableReason> _unavailableReasons;
QString _phone;
ContactStatus _contactStatus = ContactStatus::Unknown;
CallsStatus _callsStatus = CallsStatus::Unknown;
int _commonChatsCount = 0;
uint64 _accessHash = 0;
static constexpr auto kInaccessibleAccessHashOld
= 0xFFFFFFFFFFFFFFFFULL;
DocumentId _emojiStatusId = 0;
};
namespace Data {
void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update);
} // namespace Data