Use isConstant bool instead of ContactStatus enum.

This commit is contained in:
John Preston 2019-06-06 19:48:42 +03:00
parent 14b82698f8
commit 30dea3a2e7
9 changed files with 35 additions and 71 deletions

View File

@ -743,8 +743,7 @@ void ApiWrap::requestContacts() {
const auto userId = contact.c_contact().vuser_id.v;
if (userId == _session->userId()) {
_session->user()->setContactStatus(
UserData::ContactStatus::Contact);
_session->user()->setIsContact(true);
}
}
_session->data().contactsLoaded() = true;

View File

@ -362,8 +362,7 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
return nullptr;
}();
if (user) {
if (user->contactStatus() == UserData::ContactStatus::Contact
|| user->session().supportMode()) {
if (user->isContact() || user->session().supportMode()) {
Ui::showPeerHistory(user, ShowAtTheEndMsgId);
}
Ui::hideLayer();

View File

@ -309,7 +309,7 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
}
result->setBotInfoVersion(-1);
status = &emptyStatus;
result->setContactStatus(UserData::ContactStatus::PhoneUnknown);
result->setIsContact(false);
if (canShareThisContact != result->canShareThisContactFast()) {
update.flags |= UpdateFlag::UserCanShareContact;
}
@ -371,15 +371,16 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
&& !data.is_mutual_contact();
auto showPhoneChanged = !result->isServiceUser()
&& !data.is_self()
&& ((showPhone
&& result->contactStatus() == UserData::ContactStatus::Contact)
&& ((showPhone && result->isContact())
|| (!showPhone
&& result->contactStatus() == UserData::ContactStatus::CanAdd));
&& !result->isContact()
&& !result->phone().isEmpty()));
if (minimal) {
showPhoneChanged = false;
showPhone = !result->isServiceUser()
&& (result->id != _session->userPeerId())
&& (result->contactStatus() == UserData::ContactStatus::CanAdd);
&& !result->isContact()
&& !result->phone().isEmpty()
&& (result->id != _session->userPeerId());
}
// see also Local::readPeer
@ -416,11 +417,8 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
} else {
result->setBotInfoVersion(-1);
}
result->setContactStatus((data.is_contact() || data.is_mutual_contact())
? UserData::ContactStatus::Contact
: result->phone().isEmpty()
? UserData::ContactStatus::PhoneUnknown
: UserData::ContactStatus::CanAdd);
result->setIsContact(data.is_contact()
|| data.is_mutual_contact());
}
if (canShareThisContact != result->canShareThisContactFast()) {
@ -448,11 +446,6 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
}
}
if (result->contactStatus() == UserData::ContactStatus::PhoneUnknown
&& !result->phone().isEmpty()
&& !result->isSelf()) {
result->setContactStatus(UserData::ContactStatus::CanAdd);
}
if (App::main()) {
if (update.flags) {
update.peer = result;
@ -1013,7 +1006,7 @@ void Session::setupUserIsContactViewer() {
"userIsContactChanged() called for a not loaded user!"));
return;
}
if (user->contactStatus() == UserData::ContactStatus::Contact) {
if (user->isContact()) {
const auto history = user->owner().history(user->id);
_contactsList.addByName(history);
if (!history->inChatList()) {

View File

@ -58,18 +58,14 @@ bool UserData::canShareThisContact() const {
|| !owner().findContactPhone(peerToUser(id)).isEmpty();
}
void UserData::setContactStatus(ContactStatus status) {
if (_contactStatus != status) {
const auto changed = (_contactStatus == ContactStatus::Contact)
!= (status == ContactStatus::Contact);
_contactStatus = status;
if (changed) {
Notify::peerUpdatedDelayed(
this,
Notify::PeerUpdate::Flag::UserIsContact);
}
void UserData::setIsContact(bool is) {
if (_isContact != is) {
_isContact = is;
Notify::peerUpdatedDelayed(
this,
Notify::PeerUpdate::Flag::UserIsContact);
}
if (_contactStatus == ContactStatus::Contact
if (_isContact
&& cReportSpamStatuses().value(id, dbiprsHidden) != dbiprsHidden) {
cRefReportSpamStatuses().insert(id, dbiprsHidden);
Local::writeReportSpamStatuses();
@ -262,6 +258,7 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
user->owner().processPhoto(update.vprofile_photo);
}
update.vsettings.match([&](const MTPDpeerSettings &data) {
//user->owner().processUserSettings(data);
//App::feedUserLink(
// MTP_int(peerToUser(user->id)),
// link.vmy_link,

View File

@ -138,9 +138,6 @@ public:
// Duplicated in Data::CanWriteValue().
return !isInaccessible();
}
bool isContact() const {
return (_contactStatus == ContactStatus::Contact);
}
bool canShareThisContact() const;
bool canAddContact() const {
@ -166,15 +163,10 @@ public:
Text phoneText;
TimeId onlineTill = 0;
enum class ContactStatus : char {
PhoneUnknown,
CanAdd,
Contact,
};
ContactStatus contactStatus() const {
return _contactStatus;
[[nodiscard]] bool isContact() const {
return _isContact;
}
void setContactStatus(ContactStatus status);
void setIsContact(bool is);
enum class BlockStatus : char {
Unknown,
@ -217,7 +209,7 @@ private:
QString _unavailableReason;
QString _phone;
ContactStatus _contactStatus = ContactStatus::PhoneUnknown;
bool _isContact = false;
BlockStatus _blockStatus = BlockStatus::Unknown;
CallsStatus _callsStatus = CallsStatus::Unknown;
int _commonChatsCount = 0;

View File

@ -1960,8 +1960,7 @@ void HistoryWidget::updateReportSpamStatus() {
if (i != cReportSpamStatuses().cend()) {
if (i.value() == dbiprsNoButton) {
setReportSpamStatus(dbiprsHidden);
if (!_peer->isUser()
|| _peer->asUser()->contactStatus() != UserData::ContactStatus::Contact) {
if (!_peer->isUser() || !_peer->asUser()->isContact()) {
MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input));
}
@ -1979,8 +1978,7 @@ void HistoryWidget::updateReportSpamStatus() {
if (i != cReportSpamStatuses().cend()) {
if (i.value() == dbiprsNoButton) {
setReportSpamStatus(dbiprsHidden);
if (!_peer->isUser()
|| _peer->asUser()->contactStatus() != UserData::ContactStatus::Contact) {
if (!_peer->isUser() || !_peer->asUser()->isContact()) {
MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input));
}
} else {
@ -1998,8 +1996,7 @@ void HistoryWidget::updateReportSpamStatus() {
auto status = dbiprsRequesting;
if (!session().data().contactsLoaded().current() || _firstLoadRequest) {
status = dbiprsUnknown;
} else if (_peer->isUser()
&& _peer->asUser()->contactStatus() == UserData::ContactStatus::Contact) {
} else if (_peer->isUser() && _peer->asUser()->isContact()) {
status = dbiprsHidden;
} else {
requestReportSpamSetting();

View File

@ -107,8 +107,7 @@ QSize HistoryContact::countOptimalSize() {
: Data::FakePeerIdForJustName(full)),
full);
}
if (_contact
&& _contact->contactStatus() == UserData::ContactStatus::Contact) {
if (_contact && _contact->isContact()) {
_linkl = sendMessageClickHandler(_contact);
_link = lang(lng_profile_send_message).toUpper();
} else if (_userId) {

View File

@ -4181,7 +4181,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateUserName: {
auto &d = update.c_updateUserName();
if (auto user = session().data().userLoaded(d.vuser_id.v)) {
if (user->contactStatus() != UserData::ContactStatus::Contact) {
if (!user->isContact()) {
user->setName(
TextUtilities::SingleLine(qs(d.vfirst_name)),
TextUtilities::SingleLine(qs(d.vlast_name)),
@ -4234,15 +4234,15 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} break;
case mtpc_updateUserPhone: {
auto &d = update.c_updateUserPhone();
if (auto user = session().data().userLoaded(d.vuser_id.v)) {
auto newPhone = qs(d.vphone);
const auto &d = update.c_updateUserPhone();
if (const auto user = session().data().userLoaded(d.vuser_id.v)) {
const auto newPhone = qs(d.vphone);
if (newPhone != user->phone()) {
user->setPhone(newPhone);
user->setName(
user->firstName,
user->lastName,
((user->contactStatus() == UserData::ContactStatus::Contact
((user->isContact()
|| user->isServiceUser()
|| user->isSelf()
|| user->phone().isEmpty())

View File

@ -128,17 +128,9 @@ void writePeer(QDataStream &stream, PeerData *peer) {
: QString();
stream << botInlinePlaceholder;
}
const auto contactSerialized = [&] {
switch (user->contactStatus()) {
case UserData::ContactStatus::Contact: return 1;
case UserData::ContactStatus::CanAdd: return 0;
case UserData::ContactStatus::PhoneUnknown: return -1;
}
Unexpected("contactStatus in _writePeer()");
}();
stream
<< qint32(user->onlineTill)
<< qint32(contactSerialized)
<< qint32(user->isContact() ? 1 : 0)
<< qint32(user->botInfo ? user->botInfo->version : -1);
} else if (const auto chat = peer->asChat()) {
stream
@ -209,11 +201,7 @@ PeerData *readPeer(int streamAppVersion, QDataStream &stream) {
user->setFlags(MTPDuser::Flags::from_raw(flags));
user->setAccessHash(access);
user->onlineTill = onlineTill;
user->setContactStatus((contact > 0)
? UserData::ContactStatus::Contact
: (contact == 0)
? UserData::ContactStatus::CanAdd
: UserData::ContactStatus::PhoneUnknown);
user->setIsContact(contact == 1);
user->setBotInfoVersion(botInfoVersion);
if (!inlinePlaceholder.isEmpty() && user->botInfo) {
user->botInfo->inlinePlaceholder = inlinePlaceholder;