From 4d7e90f7e93afcc10e92558a897924864b0b16fa Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 2 Sep 2015 13:20:33 +0300 Subject: [PATCH] fixed adding contacts from shared contacts --- Telegram/SourceFiles/app.cpp | 12 ++++++++++++ Telegram/SourceFiles/app.h | 3 +++ Telegram/SourceFiles/boxes/addcontactbox.cpp | 1 - Telegram/SourceFiles/dialogswidget.cpp | 17 ++++++----------- Telegram/SourceFiles/dialogswidget.h | 2 +- Telegram/SourceFiles/history.cpp | 8 ++------ Telegram/SourceFiles/mainwidget.cpp | 4 ++-- Telegram/SourceFiles/profilewidget.cpp | 4 ++-- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index a4a79a4262..3c0016f482 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -70,6 +70,9 @@ namespace { typedef QMap > RepliesTo; RepliesTo repliesTo; + typedef QMap SharedContactPhones; + SharedContactPhones sharedContactPhones; + Histories histories; typedef QHash MsgsData; @@ -1725,6 +1728,7 @@ namespace App { ::audioItems.clear(); ::documentItems.clear(); ::webPageItems.clear(); + ::sharedContactPhones.clear(); ::repliesTo.clear(); lastPhotos.clear(); lastPhotosMap.clear(); @@ -2117,6 +2121,14 @@ namespace App { return ::webPageItems; } + void regSharedContactPhone(int32 userId, const QString &phone) { + ::sharedContactPhones[userId] = phone; + } + + QString phoneFromSharedContact(int32 userId) { + return ::sharedContactPhones.value(userId); + } + void regMuted(PeerData *peer, int32 changeIn) { ::mutedPeers.insert(peer, true); if (App::main()) App::main()->updateMutedIn(changeIn); diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 10465c71db..f14f280ebd 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -248,6 +248,9 @@ namespace App { void unregWebPageItem(WebPageData *data, HistoryItem *item); const WebPageItems &webPageItems(); + void regSharedContactPhone(int32 userId, const QString &phone); + QString phoneFromSharedContact(int32 userId); + void regMuted(PeerData *peer, int32 changeIn); void unregMuted(PeerData *peer); void updateMuted(); diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 75353e55e8..0694a143c5 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -285,7 +285,6 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { } if (uid) { App::main()->addNewContact(uid); - App::main()->choosePeer(App::peerFromUser(uid), ShowAtUnreadMsgId); App::wnd()->hideLayer(); } else { _addButton.hide(); diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index f2c626da43..58ef6fc7e1 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -829,22 +829,17 @@ void DialogsListWidget::contactsReceived(const QVector &contacts) { refresh(); } -int32 DialogsListWidget::addNewContact(int32 uid, bool select) { +int32 DialogsListWidget::addNewContact(int32 uid, bool select) { // -2 - err, -1 - don't scroll, >= 0 - scroll PeerId peer = App::peerFromUser(uid); - if (!App::peerLoaded(peer)) return -1; + if (!App::peerLoaded(peer)) return -2; History *history = App::history(peer); contacts.addByName(history); DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(peer); if (i == dialogs.list.rowByPeer.cend()) { DialogRow *added = contactsNoDialogs.addByName(history); - if (!added) return -1; - if (select && false) { - sel = added; - contactSel = true; - } -// if (contactsNoDialogs.list.count == 1 && !dialogs.list.count) refresh(); - return added ? ((dialogs.list.count + added->pos) * st::dlgHeight) : -1; + if (!added) return -2; + return -1; } if (select) { sel = i.value(); @@ -1842,9 +1837,9 @@ bool DialogsWidget::addNewContact(int32 uid, bool show) { _filter.setText(QString()); onFilterUpdate(); int32 to = list.addNewContact(uid, true); - if (to < 0 || !show) return false; + if (to < -1 || !show) return false; list.refresh(); - scroll.scrollToY(to); + if (to >= 0) scroll.scrollToY(to); return true; } diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index 036a7695a9..bca3487276 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -35,7 +35,7 @@ public: void activate(); void contactsReceived(const QVector &contacts); - int32 addNewContact(int32 uid, bool sel = false); // return y of row or -1 if failed + int32 addNewContact(int32 uid, bool sel = false); // -2 - err, -1 - don't scroll, >= 0 - scroll int32 filteredOffset() const; int32 peopleOffset() const; diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 097d4e5dcc..5124359066 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -3664,18 +3664,14 @@ HistoryContact::HistoryContact(int32 userId, const QString &first, const QString , phone(App::formatPhone(phone)) , contact(App::userLoaded(userId)) { + App::regSharedContactPhone(userId, phone); + _maxw = st::mediaMaxWidth; name.setText(st::mediaFont, (first + ' ' + last).trimmed(), _textNameOptions); phonew = st::mediaFont->m.width(phone); if (contact) { - if (contact->phone.isEmpty()) { - contact->setPhone(phone); - } - if (contact->contact < 0) { - contact->contact = 0; - } contact->photo->load(); } } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 5f9de2fc6a..8e273cf686 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -78,7 +78,7 @@ void TopBarWidget::onInfoClicked() { void TopBarWidget::onAddContact() { PeerData *p = App::main() ? App::main()->profilePeer() : 0; UserData *u = (p && !p->chat) ? p->asUser() : 0; - if (u) App::wnd()->showLayer(new AddContactBox(u->firstName, u->lastName, u->phone)); + if (u) App::wnd()->showLayer(new AddContactBox(u->firstName, u->lastName, u->phone.isEmpty() ? App::phoneFromSharedContact(App::userFromPeer(u->id)) : u->phone)); } void TopBarWidget::onEdit() { @@ -278,7 +278,7 @@ void TopBarWidget::showAll() { return; } PeerData *p = App::main() ? App::main()->profilePeer() : 0, *o = App::main() ? App::main()->overviewPeer() : 0; - if (p && (p->chat || p->asUser()->contact >= 0)) { + if (p && (p->chat || p->asUser()->contact >= 0 || !App::phoneFromSharedContact(App::userFromPeer(p->id)).isEmpty())) { if (p->chat) { if (p->asChat()->forbidden) { _edit.hide(); diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 28f8f275cc..023b71e402 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -82,7 +82,7 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee if (_peerUser->blocked == UserIsBlocked) { _blockUser.setText(lang(_peerUser->botInfo ? lng_profile_unblock_bot : lng_profile_unblock_user)); } - _phoneText = App::formatPhone(_peerUser->phone); + _phoneText = App::formatPhone(_peerUser->phone.isEmpty() ? App::phoneFromSharedContact(App::userFromPeer(_peerUser->id)) : _peerUser->phone); PhotoData *userPhoto = (_peerUser->photoId && _peerUser->photoId != UnknownPeerPhotoId) ? App::photo(_peerUser->photoId) : 0; if (userPhoto && userPhoto->date) { _photoLink = TextLinkPtr(new PhotoLink(userPhoto, _peer)); @@ -434,7 +434,7 @@ void ProfileInner::peerUpdated(PeerData *data) { if (data == _peer) { PhotoData *photo = 0; if (_peerUser) { - _phoneText = App::formatPhone(_peerUser->phone); + _phoneText = App::formatPhone(_peerUser->phone.isEmpty() ? App::phoneFromSharedContact(App::userFromPeer(_peerUser->id)) : _peerUser->phone); if (_peerUser->photoId && _peerUser->photoId != UnknownPeerPhotoId) photo = App::photo(_peerUser->photoId); if (_wasBlocked != _peerUser->blocked) { _wasBlocked = _peerUser->blocked;