diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp index 5ed28082e2cbac1ea5800f401f84c65716931585..11ff56f659889b2ccabdc8294db0c9a2230fbc6d 100644 --- a/src/accountmodel.cpp +++ b/src/accountmodel.cpp @@ -470,11 +470,12 @@ void AccountModelPrivate::slotIncomingContactRequest(const QString& accountId, c return; } - auto contactMethod = PhoneDirectoryModel::instance().getNumber(ringID, a); - auto person = VCardUtils::mapToPersonFromReceivedProfile(contactMethod, payload); - - ContactRequest* r = new ContactRequest(a, person, ringID, time); + /* do not pass a person before the contact request was added to his model */ + ContactRequest* r = new ContactRequest(a, nullptr, ringID, time); a->pendingContactRequestModel()->d_ptr->addRequest(r); + + auto contactMethod = PhoneDirectoryModel::instance().getNumber(ringID, a); + r->setPeer(VCardUtils::mapToPersonFromReceivedProfile(contactMethod, payload)); } ///Known Ring devices have changed diff --git a/src/pendingcontactrequestmodel.cpp b/src/pendingcontactrequestmodel.cpp index a04caade87087bb3343e106f7d5325367c97560e..bb65b3cceb41028ca060643a3a70b4dee6c47894 100644 --- a/src/pendingcontactrequestmodel.cpp +++ b/src/pendingcontactrequestmodel.cpp @@ -27,6 +27,7 @@ #include "private/pendingcontactrequestmodel_p.h" #include "person.h" #include "contactmethod.h" +#include "uri.h" PendingContactRequestModelPrivate::PendingContactRequestModelPrivate(PendingContactRequestModel* p) : q_ptr(p) {} @@ -161,3 +162,13 @@ void PendingContactRequestModelPrivate::removeRequest(ContactRequest* r) m_lRequests.removeAt(index); q_ptr->endRemoveRows(); } + +ContactRequest* +PendingContactRequestModel::findContactRequestFrom(const ContactMethod* cm) const +{ + auto iter = std::find_if(d_ptr->m_lRequests.begin(), d_ptr->m_lRequests.end(), + [&](ContactRequest* r){ return r->certificate()->remoteId() == cm->uri(); }); + if (iter != std::end(d_ptr->m_lRequests)) + return *iter; + return nullptr; +} diff --git a/src/pendingcontactrequestmodel.h b/src/pendingcontactrequestmodel.h index 2e90173fff526588376e49d9cb74a741e2e6da54..96be7026969602f4b7e3b582d4b3bd47e3d20461 100644 --- a/src/pendingcontactrequestmodel.h +++ b/src/pendingcontactrequestmodel.h @@ -23,6 +23,7 @@ class Account; class PendingContactRequestModelPrivate; class ContactRequest; +class ContactMethod; /** * List the pending (incoming) trust request for an account @@ -51,6 +52,9 @@ public: virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; virtual QHash<int,QByteArray> roleNames() const override; + // Helper + ContactRequest* findContactRequestFrom(const ContactMethod* cm) const; + private: explicit PendingContactRequestModel(Account* a); virtual ~PendingContactRequestModel(); diff --git a/src/recentmodel.cpp b/src/recentmodel.cpp index 85a8500d7419127c3a534ea59c34eea29911fe6e..014ed9466870a766689bfd8613683068d1fd052d 100644 --- a/src/recentmodel.cpp +++ b/src/recentmodel.cpp @@ -41,6 +41,7 @@ #include "contactrequest.h" #include "certificate.h" #include "availableaccountmodel.h" +#include "pendingcontactrequestmodel.h" struct CallGroup { @@ -775,7 +776,10 @@ void RecentModelPrivate::slotContactChanged(ContactMethod* contactMethod, const // TODO: implement for when the Person of the CM changes, ie: oldPerson != nullptr Q_UNUSED(oldPerson) - if (!newPerson) return; + if (not newPerson + or /* avoid to add en entry in recent model when a person was built for a contact request */ + contactMethod->account()->pendingContactRequestModel()->findContactRequestFrom(contactMethod)) + return; // make sure the Person node exists first, then move any children of the CM nodes slotLastUsedTimeChanged(newPerson, newPerson->lastUsedTime());