Remove Notify::userIsContactChanged().

Replace with Notify::peerUpdatedDelayed().
This commit is contained in:
John Preston 2018-01-04 12:21:06 +03:00
parent 139ef5411a
commit 46612ef128
18 changed files with 249 additions and 134 deletions

View File

@ -325,10 +325,8 @@ void ApiWrap::requestContacts() {
const auto userId = contact.c_contact().vuser_id.v;
if (userId == Auth().userId() && App::self()) {
if (App::self()->contact < 1) {
App::self()->contact = 1;
Notify::userIsContactChanged(App::self());
}
App::self()->setContactStatus(
UserData::ContactStatus::Contact);
}
}
_session->data().contactsLoaded().set(true);

View File

@ -234,7 +234,7 @@ namespace {
UserData *feedUser(const MTPUser &user) {
UserData *data = nullptr;
bool wasContact = false, minimal = false;
bool minimal = false;
const MTPUserStatus *status = 0, emptyStatus = MTP_userStatusEmpty();
Notify::PeerUpdate update;
@ -247,7 +247,6 @@ namespace {
auto peer = peerFromUser(d.vid.v);
data = App::user(peer);
auto canShareThisContact = data->canShareThisContactFast();
wasContact = data->isContact();
data->input = MTP_inputPeerUser(d.vid, MTP_long(0));
data->inputUser = MTP_inputUser(d.vid, MTP_long(0));
@ -255,12 +254,17 @@ namespace {
data->setPhoto(MTP_userProfilePhotoEmpty());
//data->setFlags(MTPDuser_ClientFlag::f_inaccessible | 0);
data->setFlags(MTPDuser::Flag::f_deleted);
if (!data->phone().isEmpty()) {
data->setPhone(QString());
update.flags |= UpdateFlag::UserPhoneChanged;
}
data->setBotInfoVersion(-1);
status = &emptyStatus;
data->contact = -1;
data->setContactStatus(UserData::ContactStatus::PhoneUnknown);
if (canShareThisContact != data->canShareThisContactFast()) update.flags |= UpdateFlag::UserCanShareContact;
if (wasContact != data->isContact()) update.flags |= UpdateFlag::UserIsContact;
if (canShareThisContact != data->canShareThisContactFast()) {
update.flags |= UpdateFlag::UserCanShareContact;
}
} break;
case mtpc_user: {
auto &d = user.c_user();
@ -269,7 +273,6 @@ namespace {
auto peer = peerFromUser(d.vid.v);
data = App::user(peer);
auto canShareThisContact = data->canShareThisContactFast();
wasContact = data->isContact();
if (minimal) {
auto mask = 0
//| MTPDuser_ClientFlag::f_inaccessible
@ -318,16 +321,30 @@ namespace {
}
bool nameChanged = (data->firstName != fname) || (data->lastName != lname);
bool showPhone = !isServiceUser(data->id) && !d.is_self() && !d.is_contact() && !d.is_mutual_contact();
bool showPhoneChanged = !isServiceUser(data->id) && !d.is_self() && ((showPhone && data->contact) || (!showPhone && !data->contact));
bool showPhone = !isServiceUser(data->id)
&& !d.is_self()
&& !d.is_contact()
&& !d.is_mutual_contact();
bool showPhoneChanged = !isServiceUser(data->id)
&& !d.is_self()
&& ((showPhone
&& data->contactStatus() == UserData::ContactStatus::Contact)
|| (!showPhone
&& data->contactStatus() == UserData::ContactStatus::CanAdd));
if (minimal) {
showPhoneChanged = false;
showPhone = !isServiceUser(data->id) && (data->id != Auth().userPeerId()) && !data->contact;
showPhone = !isServiceUser(data->id)
&& (data->id != Auth().userPeerId())
&& (data->contactStatus() == UserData::ContactStatus::CanAdd);
}
// see also Local::readPeer
QString pname = (showPhoneChanged || phoneChanged || nameChanged) ? ((showPhone && !phone.isEmpty()) ? formatPhone(phone) : QString()) : data->nameOrPhone;
const auto pname = (showPhoneChanged || phoneChanged || nameChanged)
? ((showPhone && !phone.isEmpty())
? formatPhone(phone)
: QString())
: data->nameOrPhone;
if (!minimal && d.is_self() && uname != data->username) {
CrashReports::SetAnnotation("Username", uname);
@ -355,19 +372,20 @@ namespace {
} else {
data->setBotInfoVersion(-1);
}
data->contact = (d.is_contact() || d.is_mutual_contact()) ? 1 : (data->phone().isEmpty() ? -1 : 0);
if (data->contact == 1 && cReportSpamStatuses().value(data->id, dbiprsHidden) != dbiprsHidden) {
cRefReportSpamStatuses().insert(data->id, dbiprsHidden);
Local::writeReportSpamStatuses();
}
data->setContactStatus((d.is_contact() || d.is_mutual_contact())
? UserData::ContactStatus::Contact
: data->phone().isEmpty()
? UserData::ContactStatus::PhoneUnknown
: UserData::ContactStatus::CanAdd);
if (d.is_self() && ::self != data) {
::self = data;
Global::RefSelfChanged().notify();
}
}
if (canShareThisContact != data->canShareThisContactFast()) update.flags |= UpdateFlag::UserCanShareContact;
if (wasContact != data->isContact()) update.flags |= UpdateFlag::UserIsContact;
if (canShareThisContact != data->canShareThisContactFast()) {
update.flags |= UpdateFlag::UserCanShareContact;
}
} break;
}
@ -392,13 +410,12 @@ namespace {
}
}
if (data->contact < 0 && !data->phone().isEmpty() && data->id != Auth().userPeerId()) {
data->contact = 0;
if (data->contactStatus() == UserData::ContactStatus::PhoneUnknown
&& !data->phone().isEmpty()
&& data->id != Auth().userPeerId()) {
data->setContactStatus(UserData::ContactStatus::CanAdd);
}
if (App::main()) {
if ((data->contact > 0 && !wasContact) || (wasContact && data->contact < 1)) {
Notify::userIsContactChanged(data);
}
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
@ -1082,43 +1099,40 @@ namespace {
}
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) {
UserData *user = userLoaded(userId.v);
if (user) {
auto wasContact = user->isContact();
bool wasShowPhone = !user->contact;
if (const auto user = userLoaded(userId.v)) {
const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd);
switch (myLink.type()) {
case mtpc_contactLinkContact:
user->contact = 1;
if (user->contact == 1 && cReportSpamStatuses().value(user->id, dbiprsHidden) != dbiprsHidden) {
cRefReportSpamStatuses().insert(user->id, dbiprsHidden);
Local::writeReportSpamStatuses();
}
user->setContactStatus(UserData::ContactStatus::Contact);
break;
case mtpc_contactLinkHasPhone:
user->contact = 0;
user->setContactStatus(UserData::ContactStatus::CanAdd);
break;
case mtpc_contactLinkNone:
case mtpc_contactLinkUnknown:
user->contact = -1;
user->setContactStatus(UserData::ContactStatus::PhoneUnknown);
break;
}
if (user->contact < 1) {
if (user->contact < 0 && !user->phone().isEmpty() && user->id != Auth().userPeerId()) {
user->contact = 0;
}
if (user->contactStatus() == UserData::ContactStatus::PhoneUnknown
&& !user->phone().isEmpty()
&& user->id != Auth().userPeerId()) {
user->setContactStatus(UserData::ContactStatus::CanAdd);
}
if (wasContact != user->isContact()) {
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserIsContact);
}
if ((user->contact > 0 && !wasContact) || (wasContact && user->contact < 1)) {
Notify::userIsContactChanged(user);
}
bool showPhone = !isServiceUser(user->id) && !user->isSelf() && !user->contact;
bool showPhoneChanged = !isServiceUser(user->id) && !user->isSelf() && ((showPhone && !wasShowPhone) || (!showPhone && wasShowPhone));
const auto showPhone = !isServiceUser(user->id)
&& !user->isSelf()
&& user->contactStatus() == UserData::ContactStatus::CanAdd;
const auto showPhoneChanged = !isServiceUser(user->id)
&& !user->isSelf()
&& (showPhone != wasShowPhone);
if (showPhoneChanged) {
user->setName(TextUtilities::SingleLine(user->firstName), TextUtilities::SingleLine(user->lastName), showPhone ? App::formatPhone(user->phone()) : QString(), TextUtilities::SingleLine(user->username));
user->setName(
TextUtilities::SingleLine(user->firstName),
TextUtilities::SingleLine(user->lastName),
showPhone
? App::formatPhone(user->phone())
: QString(),
TextUtilities::SingleLine(user->username));
}
}
}

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/section_widget.h"
#include "chat_helpers/tabbed_selector.h"
#include "boxes/send_files_box.h"
#include "observer_peer.h"
namespace {
@ -30,6 +31,20 @@ constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000);
} // namespace
AuthSessionData::AuthSessionData() {
Notify::PeerUpdateViewer(
Notify::PeerUpdate::Flag::UserIsContact
) | rpl::map([](const Notify::PeerUpdate &update) {
return update.peer->asUser();
}) | rpl::filter([](UserData *user) {
return user != nullptr;
}) | rpl::start_with_next([=](not_null<UserData*> user) {
userIsContactUpdated(user);
}, _lifetime);
}
AuthSessionData::~AuthSessionData() = default;
AuthSessionData::Variables::Variables()
: sendFilesWay(SendFilesWay::Album)
, selectorTab(ChatHelpers::SelectorTab::Emoji)
@ -354,6 +369,16 @@ rpl::producer<> AuthSessionData::savedGifsUpdated() const {
return _savedGifsUpdated.events();
}
void AuthSessionData::userIsContactUpdated(not_null<UserData*> user) {
const auto &items = App::sharedContactItems();
const auto i = items.constFind(peerToUser(user->id));
if (i != items.cend()) {
for (const auto item : std::as_const(i.value())) {
item->setPendingInitDimensions();
}
}
}
HistoryItemsList AuthSessionData::idsToItems(
const MessageIdsList &ids) const {
return ranges::view::all(

View File

@ -43,6 +43,9 @@ class Changelogs;
class AuthSessionData final {
public:
AuthSessionData();
~AuthSessionData();
base::Variable<bool> &contactsLoaded() {
return _contactsLoaded;
}
@ -293,6 +296,7 @@ private:
return (lastUpdate == 0)
|| (now >= lastUpdate + kStickersUpdateTimeout);
}
void userIsContactUpdated(not_null<UserData*> user);
base::Variable<bool> _contactsLoaded = { false };
base::Variable<bool> _allChatsLoaded = { false };
@ -328,6 +332,8 @@ private:
Variables _variables;
TimeMs _lastTimeVideoPlayedAt = 0;
rpl::lifetime _lifetime;
};
// One per Messenger.

View File

@ -241,19 +241,23 @@ bool AddContactBox::onSaveUserFail(const RPCError &error) {
void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
if (!isBoxShown() || !App::main()) return;
auto &d = res.c_contacts_importedContacts();
const auto &d = res.c_contacts_importedContacts();
App::feedUsers(d.vusers);
auto &v = d.vimported.v;
UserData *user = nullptr;
if (!v.isEmpty()) {
auto &c = v.front().c_importedContact();
if (c.vclient_id.v != _contactId) return;
user = App::userLoaded(c.vuser_id.v);
}
const auto &v = d.vimported.v;
const auto user = [&]() -> UserData* {
if (!v.isEmpty()) {
auto &c = v.front().c_importedContact();
if (c.vclient_id.v == _contactId) {
return App::userLoaded(c.vuser_id.v);
}
}
return nullptr;
}();
if (user) {
Notify::userIsContactChanged(user, true);
if (user->contactStatus() == UserData::ContactStatus::Contact) {
Ui::showPeerHistory(user, ShowAtTheEndMsgId);
}
Ui::hideLayer();
} else {
hideChildren();

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "messenger.h"
#include "mainwindow.h"
#include "window/window_controller.h"
#include "storage/localstorage.h"
#include "ui/empty_userpic.h"
#include "ui/text_options.h"
@ -348,7 +349,26 @@ const Text &BotCommand::descriptionText() const {
}
bool UserData::canShareThisContact() const {
return canShareThisContactFast() || !App::phoneFromSharedContact(peerToUser(id)).isEmpty();
return canShareThisContactFast()
|| !App::phoneFromSharedContact(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);
}
}
if (_contactStatus == ContactStatus::Contact
&& cReportSpamStatuses().value(id, dbiprsHidden) != dbiprsHidden) {
cRefReportSpamStatuses().insert(id, dbiprsHidden);
Local::writeReportSpamStatuses();
}
}
// see Local::readPeer as well

View File

@ -384,7 +384,7 @@ public:
return !isInaccessible();
}
bool isContact() const {
return (contact > 0);
return (_contactStatus == ContactStatus::Contact);
}
bool canShareThisContact() const;
@ -410,9 +410,18 @@ public:
QString nameOrPhone;
Text phoneText;
TimeId onlineTill = 0;
int32 contact = -1; // -1 - not contact, cant add (self, empty, deleted, foreign), 0 - not contact, can add (request), 1 - contact
enum class BlockStatus {
enum class ContactStatus : char {
PhoneUnknown,
CanAdd,
Contact,
};
ContactStatus contactStatus() const {
return _contactStatus;
}
void setContactStatus(ContactStatus status);
enum class BlockStatus : char {
Unknown,
Blocked,
NotBlocked,
@ -425,7 +434,7 @@ public:
}
void setBlockStatus(BlockStatus blockStatus);
enum class CallsStatus {
enum class CallsStatus : char {
Unknown,
Enabled,
Disabled,
@ -461,6 +470,7 @@ private:
QString _restrictionReason;
QString _about;
QString _phone;
ContactStatus _contactStatus = ContactStatus::PhoneUnknown;
BlockStatus _blockStatus = BlockStatus::Unknown;
CallsStatus _callsStatus = CallsStatus::Unknown;
int _commonChatsCount = 0;

View File

@ -109,7 +109,8 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::PinnedChanged
| UpdateFlag::NameChanged
| UpdateFlag::PhotoChanged;
| UpdateFlag::PhotoChanged
| UpdateFlag::UserIsContact;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.flags & UpdateFlag::PinnedChanged) {
stopReorderPinned();
@ -121,6 +122,11 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
this->update();
emit App::main()->dialogsUpdated();
}
if (update.flags & UpdateFlag::UserIsContact) {
if (const auto user = update.peer->asUser()) {
userIsContactUpdated(user);
}
}
}));
refresh();
@ -1073,6 +1079,7 @@ void DialogsInner::createDialog(History *history) {
void DialogsInner::removeDialog(History *history) {
if (!history) return;
if (history->peer == _menuPeer && _menu) {
InvokeQueued(this, [this] { _menu = nullptr; });
}
@ -1636,20 +1643,17 @@ void DialogsInner::peerSearchReceived(const QString &query, const QVector<MTPPee
refresh();
}
void DialogsInner::notify_userIsContactChanged(UserData *user, bool fromThisApp) {
void DialogsInner::userIsContactUpdated(not_null<UserData*> user) {
if (user->loadedStatus != PeerData::FullLoaded) {
LOG(("API Error: notify_userIsContactChanged() called for a not loaded user!"));
LOG(("API Error: "
"notify_userIsContactChanged() called for a not loaded user!"));
return;
}
if (user->contact > 0) {
auto history = App::history(user->id);
if (user->contactStatus() == UserData::ContactStatus::Contact) {
const auto history = App::history(user->id);
_contacts->addByName(history);
if (auto row = shownDialogs()->getRow(user->id)) {
if (fromThisApp) {
_selected = row;
_importantSwitchSelected = false;
}
} else if (!_dialogs->contains(user->id)) {
if (!shownDialogs()->getRow(user->id)
&& !_dialogs->contains(user->id)) {
_contactsNoDialogs->addByName(history);
}
} else {

View File

@ -95,7 +95,6 @@ public:
base::Observable<UserData*> searchFromUserChanged;
void notify_userIsContactChanged(UserData *user, bool fromThisApp);
void notify_historyMuteUpdated(History *history);
~DialogsInner();
@ -138,6 +137,7 @@ private:
struct PeerSearchResult;
using PeerSearchResults = std::vector<std::unique_ptr<PeerSearchResult>>;
void userIsContactUpdated(not_null<UserData*> user);
void mousePressReleased(Qt::MouseButton button);
void clearIrrelevantState();
void updateSelected() {

View File

@ -300,15 +300,6 @@ void DialogsWidget::onCancel() {
}
}
void DialogsWidget::notify_userIsContactChanged(UserData *user, bool fromThisApp) {
if (fromThisApp) {
_filter->setText(QString());
_filter->updatePlaceholder();
onFilterUpdate();
}
_inner->notify_userIsContactChanged(user, fromThisApp);
}
void DialogsWidget::notify_historyMuteUpdated(History *history) {
_inner->notify_historyMuteUpdated(history);
}

View File

@ -88,7 +88,6 @@ public:
bool wheelEventFromFloatPlayer(QEvent *e) override;
QRect rectForFloatPlayer() const override;
void notify_userIsContactChanged(UserData *user, bool fromThisApp);
void notify_historyMuteUpdated(History *history);
signals:

View File

@ -302,10 +302,6 @@ void userIsBotChanged(UserData *user) {
if (MainWidget *m = App::main()) m->notify_userIsBotChanged(user);
}
void userIsContactChanged(UserData *user, bool fromThisApp) {
if (MainWidget *m = App::main()) m->notify_userIsContactChanged(user, fromThisApp);
}
void botCommandsChanged(UserData *user) {
if (MainWidget *m = App::main()) {
m->notify_botCommandsChanged(user);

View File

@ -219,7 +219,6 @@ enum ClipStopperType {
namespace Notify {
void userIsBotChanged(UserData *user);
void userIsContactChanged(UserData *user, bool fromThisApp = false);
void botCommandsChanged(UserData *user);
void inlineBotRequesting(bool requesting);

View File

@ -3286,7 +3286,8 @@ void HistoryContact::initDimensions() {
Data::PeerUserpicColor(_userId ? _userId : _parent->id),
_name.originalText());
}
if (_contact && _contact->contact > 0) {
if (_contact
&& _contact->contactStatus() == UserData::ContactStatus::Contact) {
_linkl = sendMessageClickHandler(_contact);
_link = lang(lng_profile_send_message).toUpper();
} else if (_userId) {

View File

@ -1864,7 +1864,8 @@ void HistoryWidget::updateReportSpamStatus() {
if (i != cReportSpamStatuses().cend()) {
if (i.value() == dbiprsNoButton) {
setReportSpamStatus(dbiprsHidden);
if (!_peer->isUser() || _peer->asUser()->contact < 1) {
if (!_peer->isUser()
|| _peer->asUser()->contactStatus() != UserData::ContactStatus::Contact) {
MTP::send(MTPmessages_HideReportSpam(_peer->input));
}
@ -1882,7 +1883,8 @@ void HistoryWidget::updateReportSpamStatus() {
if (i != cReportSpamStatuses().cend()) {
if (i.value() == dbiprsNoButton) {
setReportSpamStatus(dbiprsHidden);
if (!_peer->isUser() || _peer->asUser()->contact < 1) {
if (!_peer->isUser()
|| _peer->asUser()->contactStatus() != UserData::ContactStatus::Contact) {
MTP::send(MTPmessages_HideReportSpam(_peer->input));
}
} else {
@ -1900,7 +1902,8 @@ void HistoryWidget::updateReportSpamStatus() {
auto status = dbiprsRequesting;
if (!Auth().data().contactsLoaded().value() || _firstLoadRequest) {
status = dbiprsUnknown;
} else if (_peer->isUser() && _peer->asUser()->contact > 0) {
} else if (_peer->isUser()
&& _peer->asUser()->contactStatus() == UserData::ContactStatus::Contact) {
status = dbiprsHidden;
} else {
requestReportSpamSetting();

View File

@ -829,24 +829,6 @@ void MainWidget::notify_userIsBotChanged(UserData *bot) {
_history->notify_userIsBotChanged(bot);
}
void MainWidget::notify_userIsContactChanged(UserData *user, bool fromThisApp) {
if (!user) return;
_dialogs->notify_userIsContactChanged(user, fromThisApp);
const SharedContactItems &items(App::sharedContactItems());
SharedContactItems::const_iterator i = items.constFind(peerToUser(user->id));
if (i != items.cend()) {
for_const (auto item, i.value()) {
item->setPendingInitDimensions();
}
}
if (user->contact > 0 && fromThisApp) {
Ui::showPeerHistory(user->id, ShowAtTheEndMsgId);
}
}
void MainWidget::notify_migrateUpdated(PeerData *peer) {
_history->notify_migrateUpdated(peer);
}
@ -4528,7 +4510,9 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
if (App::self()) {
App::self()->onlineTill = unixtime() + (isOnline ? (Global::OnlineUpdatePeriod() / 1000) : -1);
Notify::peerUpdatedDelayed(App::self(), Notify::PeerUpdate::Flag::UserOnlineChanged);
Notify::peerUpdatedDelayed(
App::self(),
Notify::PeerUpdate::Flag::UserOnlineChanged);
}
if (!isOnline) { // Went offline, so we need to save message draft to the cloud.
saveDraftToCloud();
@ -5157,7 +5141,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_userStatusOffline: user->onlineTill = d.vstatus.c_userStatusOffline().vwas_online.v; break;
case mtpc_userStatusOnline: user->onlineTill = d.vstatus.c_userStatusOnline().vexpires.v; break;
}
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserOnlineChanged);
Notify::peerUpdatedDelayed(
user,
Notify::PeerUpdate::Flag::UserOnlineChanged);
}
if (d.vuser_id.v == Auth().userId()) {
if (d.vstatus.type() == mtpc_userStatusOffline || d.vstatus.type() == mtpc_userStatusEmpty) {
@ -5174,10 +5160,18 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateUserName: {
auto &d = update.c_updateUserName();
if (auto user = App::userLoaded(d.vuser_id.v)) {
if (user->contact <= 0) {
user->setName(TextUtilities::SingleLine(qs(d.vfirst_name)), TextUtilities::SingleLine(qs(d.vlast_name)), user->nameOrPhone, TextUtilities::SingleLine(qs(d.vusername)));
if (user->contactStatus() != UserData::ContactStatus::Contact) {
user->setName(
TextUtilities::SingleLine(qs(d.vfirst_name)),
TextUtilities::SingleLine(qs(d.vlast_name)),
user->nameOrPhone,
TextUtilities::SingleLine(qs(d.vusername)));
} else {
user->setName(TextUtilities::SingleLine(user->firstName), TextUtilities::SingleLine(user->lastName), user->nameOrPhone, TextUtilities::SingleLine(qs(d.vusername)));
user->setName(
TextUtilities::SingleLine(user->firstName),
TextUtilities::SingleLine(user->lastName),
user->nameOrPhone,
TextUtilities::SingleLine(qs(d.vusername)));
}
}
} break;
@ -5233,9 +5227,20 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
auto newPhone = qs(d.vphone);
if (newPhone != user->phone()) {
user->setPhone(newPhone);
user->setName(user->firstName, user->lastName, (user->contact || isServiceUser(user->id) || user->isSelf() || user->phone().isEmpty()) ? QString() : App::formatPhone(user->phone()), user->username);
user->setName(
user->firstName,
user->lastName,
((user->contactStatus() == UserData::ContactStatus::Contact
|| isServiceUser(user->id)
|| user->isSelf()
|| user->phone().isEmpty())
? QString()
: App::formatPhone(user->phone())),
user->username);
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserPhoneChanged);
Notify::peerUpdatedDelayed(
user,
Notify::PeerUpdate::Flag::UserPhoneChanged);
}
}
} break;

View File

@ -330,7 +330,6 @@ public:
void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
void notify_userIsBotChanged(UserData *bot);
void notify_userIsContactChanged(UserData *user, bool fromThisApp);
void notify_migrateUpdated(PeerData *peer);
void notify_historyMuteUpdated(History *history);
@ -431,6 +430,7 @@ private:
[[nodiscard]] bool saveThirdSectionToStackBack() const;
[[nodiscard]] auto thirdSectionForCurrentMainSection(
not_null<PeerData*> peer) -> std::unique_ptr<Window::SectionMemento>;
void userIsContactUpdated(not_null<UserData*> user);
void createPlayer();
void switchToPanelPlayer();

View File

@ -4007,20 +4007,52 @@ void _writePeer(QDataStream &stream, PeerData *peer) {
stream << quint64(peer->id) << quint64(peer->userpicPhotoId());
Serialize::writeStorageImageLocation(stream, peer->userpicLocation());
if (const auto user = peer->asUser()) {
stream << user->firstName << user->lastName << user->phone() << user->username << quint64(user->accessHash());
stream
<< user->firstName
<< user->lastName
<< user->phone()
<< user->username
<< quint64(user->accessHash());
if (AppVersion >= 9012) {
stream << qint32(user->flags());
}
if (AppVersion >= 9016) {
stream << (user->botInfo ? user->botInfo->inlinePlaceholder : QString());
const auto botInlinePlaceholder = user->botInfo
? user->botInfo->inlinePlaceholder
: QString();
stream << botInlinePlaceholder;
}
stream << qint32(user->onlineTill) << qint32(user->contact) << qint32(user->botInfo ? user->botInfo->version : -1);
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->botInfo ? user->botInfo->version : -1);
} else if (const auto chat = peer->asChat()) {
stream << chat->name << qint32(chat->count) << qint32(chat->date) << qint32(chat->version) << qint32(chat->creator);
stream << qint32(0) << quint32(chat->flags()) << chat->inviteLink();
} else if (auto channel = peer->asChannel()) {
stream << channel->name << quint64(channel->access) << qint32(channel->date) << qint32(channel->version);
stream << qint32(0) << quint32(channel->flags()) << channel->inviteLink();
stream
<< chat->name
<< qint32(chat->count)
<< qint32(chat->date)
<< qint32(chat->version)
<< qint32(chat->creator)
<< qint32(0)
<< quint32(chat->flags())
<< chat->inviteLink();
} else if (const auto channel = peer->asChannel()) {
stream
<< channel->name
<< quint64(channel->access)
<< qint32(channel->date)
<< qint32(channel->version)
<< qint32(0)
<< quint32(channel->flags())
<< channel->inviteLink();
}
}
@ -4049,8 +4081,12 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
}
from.stream >> onlineTill >> contact >> botInfoVersion;
bool showPhone = !isServiceUser(user->id) && (user->id != Auth().userPeerId()) && (contact <= 0);
QString pname = (showPhone && !phone.isEmpty()) ? App::formatPhone(phone) : QString();
const auto showPhone = !isServiceUser(user->id)
&& (user->id != Auth().userPeerId())
&& (contact <= 0);
const auto pname = (showPhone && !phone.isEmpty())
? App::formatPhone(phone)
: QString();
if (!wasLoaded) {
user->setPhone(phone);
@ -4059,7 +4095,11 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
user->setFlags(MTPDuser::Flags::from_raw(flags));
user->setAccessHash(access);
user->onlineTill = onlineTill;
user->contact = contact;
user->setContactStatus((contact > 0)
? UserData::ContactStatus::Contact
: (contact == 0)
? UserData::ContactStatus::CanAdd
: UserData::ContactStatus::PhoneUnknown);
user->setBotInfoVersion(botInfoVersion);
if (!inlinePlaceholder.isEmpty() && user->botInfo) {
user->botInfo->inlinePlaceholder = inlinePlaceholder;