fixed adding contacts from shared contacts

This commit is contained in:
John Preston 2015-09-02 13:20:33 +03:00
parent ad089cb8da
commit 4d7e90f7e9
8 changed files with 28 additions and 23 deletions

View File

@ -70,6 +70,9 @@ namespace {
typedef QMap<HistoryItem*, QMap<HistoryReply*, bool> > RepliesTo; typedef QMap<HistoryItem*, QMap<HistoryReply*, bool> > RepliesTo;
RepliesTo repliesTo; RepliesTo repliesTo;
typedef QMap<int32, QString> SharedContactPhones;
SharedContactPhones sharedContactPhones;
Histories histories; Histories histories;
typedef QHash<MsgId, HistoryItem*> MsgsData; typedef QHash<MsgId, HistoryItem*> MsgsData;
@ -1725,6 +1728,7 @@ namespace App {
::audioItems.clear(); ::audioItems.clear();
::documentItems.clear(); ::documentItems.clear();
::webPageItems.clear(); ::webPageItems.clear();
::sharedContactPhones.clear();
::repliesTo.clear(); ::repliesTo.clear();
lastPhotos.clear(); lastPhotos.clear();
lastPhotosMap.clear(); lastPhotosMap.clear();
@ -2117,6 +2121,14 @@ namespace App {
return ::webPageItems; 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) { void regMuted(PeerData *peer, int32 changeIn) {
::mutedPeers.insert(peer, true); ::mutedPeers.insert(peer, true);
if (App::main()) App::main()->updateMutedIn(changeIn); if (App::main()) App::main()->updateMutedIn(changeIn);

View File

@ -248,6 +248,9 @@ namespace App {
void unregWebPageItem(WebPageData *data, HistoryItem *item); void unregWebPageItem(WebPageData *data, HistoryItem *item);
const WebPageItems &webPageItems(); const WebPageItems &webPageItems();
void regSharedContactPhone(int32 userId, const QString &phone);
QString phoneFromSharedContact(int32 userId);
void regMuted(PeerData *peer, int32 changeIn); void regMuted(PeerData *peer, int32 changeIn);
void unregMuted(PeerData *peer); void unregMuted(PeerData *peer);
void updateMuted(); void updateMuted();

View File

@ -285,7 +285,6 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
} }
if (uid) { if (uid) {
App::main()->addNewContact(uid); App::main()->addNewContact(uid);
App::main()->choosePeer(App::peerFromUser(uid), ShowAtUnreadMsgId);
App::wnd()->hideLayer(); App::wnd()->hideLayer();
} else { } else {
_addButton.hide(); _addButton.hide();

View File

@ -829,22 +829,17 @@ void DialogsListWidget::contactsReceived(const QVector<MTPContact> &contacts) {
refresh(); 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); PeerId peer = App::peerFromUser(uid);
if (!App::peerLoaded(peer)) return -1; if (!App::peerLoaded(peer)) return -2;
History *history = App::history(peer); History *history = App::history(peer);
contacts.addByName(history); contacts.addByName(history);
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(peer); DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(peer);
if (i == dialogs.list.rowByPeer.cend()) { if (i == dialogs.list.rowByPeer.cend()) {
DialogRow *added = contactsNoDialogs.addByName(history); DialogRow *added = contactsNoDialogs.addByName(history);
if (!added) return -1; if (!added) return -2;
if (select && false) { return -1;
sel = added;
contactSel = true;
}
// if (contactsNoDialogs.list.count == 1 && !dialogs.list.count) refresh();
return added ? ((dialogs.list.count + added->pos) * st::dlgHeight) : -1;
} }
if (select) { if (select) {
sel = i.value(); sel = i.value();
@ -1842,9 +1837,9 @@ bool DialogsWidget::addNewContact(int32 uid, bool show) {
_filter.setText(QString()); _filter.setText(QString());
onFilterUpdate(); onFilterUpdate();
int32 to = list.addNewContact(uid, true); int32 to = list.addNewContact(uid, true);
if (to < 0 || !show) return false; if (to < -1 || !show) return false;
list.refresh(); list.refresh();
scroll.scrollToY(to); if (to >= 0) scroll.scrollToY(to);
return true; return true;
} }

View File

@ -35,7 +35,7 @@ public:
void activate(); void activate();
void contactsReceived(const QVector<MTPContact> &contacts); void contactsReceived(const QVector<MTPContact> &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 filteredOffset() const;
int32 peopleOffset() const; int32 peopleOffset() const;

View File

@ -3664,18 +3664,14 @@ HistoryContact::HistoryContact(int32 userId, const QString &first, const QString
, phone(App::formatPhone(phone)) , phone(App::formatPhone(phone))
, contact(App::userLoaded(userId)) , contact(App::userLoaded(userId))
{ {
App::regSharedContactPhone(userId, phone);
_maxw = st::mediaMaxWidth; _maxw = st::mediaMaxWidth;
name.setText(st::mediaFont, (first + ' ' + last).trimmed(), _textNameOptions); name.setText(st::mediaFont, (first + ' ' + last).trimmed(), _textNameOptions);
phonew = st::mediaFont->m.width(phone); phonew = st::mediaFont->m.width(phone);
if (contact) { if (contact) {
if (contact->phone.isEmpty()) {
contact->setPhone(phone);
}
if (contact->contact < 0) {
contact->contact = 0;
}
contact->photo->load(); contact->photo->load();
} }
} }

View File

@ -78,7 +78,7 @@ void TopBarWidget::onInfoClicked() {
void TopBarWidget::onAddContact() { void TopBarWidget::onAddContact() {
PeerData *p = App::main() ? App::main()->profilePeer() : 0; PeerData *p = App::main() ? App::main()->profilePeer() : 0;
UserData *u = (p && !p->chat) ? p->asUser() : 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() { void TopBarWidget::onEdit() {
@ -278,7 +278,7 @@ void TopBarWidget::showAll() {
return; return;
} }
PeerData *p = App::main() ? App::main()->profilePeer() : 0, *o = App::main() ? App::main()->overviewPeer() : 0; 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->chat) {
if (p->asChat()->forbidden) { if (p->asChat()->forbidden) {
_edit.hide(); _edit.hide();

View File

@ -82,7 +82,7 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee
if (_peerUser->blocked == UserIsBlocked) { if (_peerUser->blocked == UserIsBlocked) {
_blockUser.setText(lang(_peerUser->botInfo ? lng_profile_unblock_bot : lng_profile_unblock_user)); _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; PhotoData *userPhoto = (_peerUser->photoId && _peerUser->photoId != UnknownPeerPhotoId) ? App::photo(_peerUser->photoId) : 0;
if (userPhoto && userPhoto->date) { if (userPhoto && userPhoto->date) {
_photoLink = TextLinkPtr(new PhotoLink(userPhoto, _peer)); _photoLink = TextLinkPtr(new PhotoLink(userPhoto, _peer));
@ -434,7 +434,7 @@ void ProfileInner::peerUpdated(PeerData *data) {
if (data == _peer) { if (data == _peer) {
PhotoData *photo = 0; PhotoData *photo = 0;
if (_peerUser) { 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 (_peerUser->photoId && _peerUser->photoId != UnknownPeerPhotoId) photo = App::photo(_peerUser->photoId);
if (_wasBlocked != _peerUser->blocked) { if (_wasBlocked != _peerUser->blocked) {
_wasBlocked = _peerUser->blocked; _wasBlocked = _peerUser->blocked;