mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 00:29:31 +00:00
fixed adding contacts from shared contacts
This commit is contained in:
parent
ad089cb8da
commit
4d7e90f7e9
@ -70,6 +70,9 @@ namespace {
|
||||
typedef QMap<HistoryItem*, QMap<HistoryReply*, bool> > RepliesTo;
|
||||
RepliesTo repliesTo;
|
||||
|
||||
typedef QMap<int32, QString> SharedContactPhones;
|
||||
SharedContactPhones sharedContactPhones;
|
||||
|
||||
Histories histories;
|
||||
|
||||
typedef QHash<MsgId, HistoryItem*> 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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -829,22 +829,17 @@ void DialogsListWidget::contactsReceived(const QVector<MTPContact> &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;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
void activate();
|
||||
|
||||
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 peopleOffset() const;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user