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"
|
2020-11-12 15:46:17 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
class BotCommand {
|
|
|
|
public:
|
|
|
|
BotCommand(const QString &command, const QString &description);
|
|
|
|
|
|
|
|
bool setDescription(const QString &description);
|
2019-06-12 13:26:04 +00:00
|
|
|
const Ui::Text::String &descriptionText() const;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
QString command;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _description;
|
2019-06-12 13:26:04 +00:00
|
|
|
mutable Ui::Text::String _descriptionText;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BotInfo {
|
|
|
|
bool inited = false;
|
|
|
|
bool readsAllHistory = false;
|
|
|
|
bool cantJoinGroups = false;
|
|
|
|
int version = 0;
|
|
|
|
QString description, inlinePlaceholder;
|
|
|
|
QList<BotCommand> commands;
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String text = { int(st::msgMinWidth) }; // description
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
QString startToken, startGroupToken, shareGameShortName;
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState inlineReturnTo;
|
2019-01-04 11:09:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class UserData : public PeerData {
|
|
|
|
public:
|
|
|
|
static constexpr auto kEssentialFlags = 0
|
|
|
|
| MTPDuser::Flag::f_self
|
|
|
|
| MTPDuser::Flag::f_contact
|
|
|
|
| MTPDuser::Flag::f_mutual_contact
|
|
|
|
| MTPDuser::Flag::f_deleted
|
|
|
|
| MTPDuser::Flag::f_bot
|
|
|
|
| MTPDuser::Flag::f_bot_chat_history
|
|
|
|
| MTPDuser::Flag::f_bot_nochats
|
|
|
|
| MTPDuser::Flag::f_verified
|
2019-06-23 12:18:33 +00:00
|
|
|
| MTPDuser::Flag::f_scam
|
2021-01-21 12:39:40 +00:00
|
|
|
| MTPDuser::Flag::f_fake
|
2019-01-04 11:09:48 +00:00
|
|
|
| MTPDuser::Flag::f_restricted
|
|
|
|
| MTPDuser::Flag::f_bot_inline_geo;
|
|
|
|
using Flags = Data::Flags<
|
|
|
|
MTPDuser::Flags,
|
|
|
|
kEssentialFlags.value()>;
|
|
|
|
|
|
|
|
static constexpr auto kEssentialFullFlags = 0
|
|
|
|
| MTPDuserFull::Flag::f_blocked
|
|
|
|
| MTPDuserFull::Flag::f_phone_calls_available
|
|
|
|
| MTPDuserFull::Flag::f_phone_calls_private;
|
|
|
|
using FullFlags = Data::Flags<
|
|
|
|
MTPDuserFull::Flags,
|
|
|
|
kEssentialFullFlags.value()>;
|
|
|
|
|
|
|
|
UserData(not_null<Data::Session*> owner, PeerId id);
|
|
|
|
void setPhoto(const MTPUserProfilePhoto &photo);
|
|
|
|
|
|
|
|
void setName(
|
|
|
|
const QString &newFirstName,
|
|
|
|
const QString &newLastName,
|
|
|
|
const QString &newPhoneName,
|
|
|
|
const QString &newUsername);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void setFlags(MTPDuser::Flags which) {
|
|
|
|
_flags.set(which);
|
|
|
|
}
|
|
|
|
void addFlags(MTPDuser::Flags which) {
|
|
|
|
_flags.add(which);
|
|
|
|
}
|
|
|
|
void removeFlags(MTPDuser::Flags which) {
|
|
|
|
_flags.remove(which);
|
|
|
|
}
|
|
|
|
auto flags() const {
|
|
|
|
return _flags.current();
|
|
|
|
}
|
|
|
|
auto flagsValue() const {
|
|
|
|
return _flags.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFullFlags(MTPDuserFull::Flags which) {
|
|
|
|
_fullFlags.set(which);
|
|
|
|
}
|
|
|
|
void addFullFlags(MTPDuserFull::Flags which) {
|
|
|
|
_fullFlags.add(which);
|
|
|
|
}
|
|
|
|
void removeFullFlags(MTPDuserFull::Flags which) {
|
|
|
|
_fullFlags.remove(which);
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] auto fullFlags() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return _fullFlags.current();
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] auto fullFlagsValue() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return _fullFlags.value();
|
|
|
|
}
|
|
|
|
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isVerified() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return flags() & MTPDuser::Flag::f_verified;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isScam() const {
|
2019-06-23 12:18:33 +00:00
|
|
|
return flags() & MTPDuser::Flag::f_scam;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isFake() const {
|
|
|
|
return flags() & MTPDuser::Flag::f_fake;
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool isBotInlineGeo() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return flags() & MTPDuser::Flag::f_bot_inline_geo;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isBot() const {
|
2019-01-13 08:03:34 +00:00
|
|
|
return botInfo != nullptr;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isSupport() const {
|
2019-03-12 10:36:33 +00:00
|
|
|
return flags() & MTPDuser::Flag::f_support;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool isInaccessible() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
constexpr auto inaccessible = 0
|
|
|
|
| MTPDuser::Flag::f_deleted;
|
|
|
|
// | MTPDuser_ClientFlag::f_inaccessible;
|
|
|
|
return flags() & inaccessible;
|
|
|
|
}
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool canWrite() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
// Duplicated in Data::CanWriteValue().
|
2020-09-11 15:33:26 +00:00
|
|
|
return !isInaccessible() && !isRepliesChat();
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool canShareThisContact() const;
|
|
|
|
[[nodiscard]] bool canAddContact() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return canShareThisContact() && !isContact();
|
|
|
|
}
|
|
|
|
|
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.
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] bool canShareThisContactFast() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return !_phone.isEmpty();
|
|
|
|
}
|
|
|
|
|
2020-09-17 15:13:12 +00:00
|
|
|
MTPInputUser inputUser = MTP_inputUserEmpty();
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
QString firstName;
|
|
|
|
QString lastName;
|
|
|
|
QString username;
|
2021-01-21 12:39:40 +00:00
|
|
|
[[nodiscard]] const QString &phone() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return _phone;
|
|
|
|
}
|
|
|
|
QString nameOrPhone;
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String phoneText;
|
2019-01-04 11:09:48 +00:00
|
|
|
TimeId onlineTill = 0;
|
|
|
|
|
2019-06-07 11:32:58 +00:00
|
|
|
enum class ContactStatus : char {
|
|
|
|
Unknown,
|
|
|
|
Contact,
|
|
|
|
NotContact,
|
|
|
|
};
|
|
|
|
[[nodiscard]] ContactStatus contactStatus() const {
|
|
|
|
return _contactStatus;
|
|
|
|
}
|
2019-06-06 16:48:42 +00:00
|
|
|
[[nodiscard]] bool isContact() const {
|
2019-06-07 11:32:58 +00:00
|
|
|
return (contactStatus() == ContactStatus::Contact);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
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,
|
|
|
|
};
|
|
|
|
CallsStatus callsStatus() const {
|
|
|
|
return _callsStatus;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
int commonChatsCount() const {
|
|
|
|
return _commonChatsCount;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
FullFlags _fullFlags;
|
|
|
|
|
2019-12-09 13:57:33 +00:00
|
|
|
std::vector<Data::UnavailableReason> _unavailableReasons;
|
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;
|
|
|
|
|
|
|
|
};
|
2019-04-23 09:40:14 +00:00
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update);
|
|
|
|
|
|
|
|
} // namespace Data
|