From 7af8969a53c74249da60cd712c81a7a4952b2f2a Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Mon, 14 Oct 2013 18:05:59 +1000 Subject: [PATCH] [libcontacts] Fetch modified contacts after link/unlink --- src/seasidecache.cpp | 35 ++++++++++++++++++++++++++--------- src/seasidecache.h | 1 + 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index 354c470..8b21504 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -2089,20 +2089,37 @@ void SeasideCache::requestStateChanged(QContactAbstractRequest::State state) qWarning() << "ID fetch completed with no filter?"; } } else if (request == &m_relationshipSaveRequest || request == &m_relationshipRemoveRequest) { - QSet contactIds; - foreach (const QContactRelationship &relationship, m_relationshipSaveRequest.relationships() + - m_relationshipRemoveRequest.relationships()) { + bool completed = false; + QList relationships; + if (request == &m_relationshipSaveRequest) { + relationships = m_relationshipSaveRequest.relationships(); + completed = !m_relationshipRemoveRequest.isActive(); + } else { + relationships = m_relationshipRemoveRequest.relationships(); + completed = !m_relationshipSaveRequest.isActive(); + } + + foreach (const QContactRelationship &relationship, relationships) { #ifdef USING_QTPIM - contactIds.insert(SeasideCache::apiId(relationship.first())); + m_aggregatedContacts.insert(SeasideCache::apiId(relationship.first())); #else - contactIds.insert(relationship.first().localId()); + m_aggregatedContacts.insert(relationship.first().localId()); #endif } - foreach (const ContactIdType &contactId, contactIds) { - CacheItem *cacheItem = itemById(contactId); - if (cacheItem && cacheItem->itemData) - cacheItem->itemData->aggregationOperationCompleted(); + if (completed) { + foreach (const ContactIdType &contactId, m_aggregatedContacts) { + CacheItem *cacheItem = itemById(contactId); + if (cacheItem && cacheItem->itemData) + cacheItem->itemData->aggregationOperationCompleted(); + } + + // We need to update these modified contacts immediately + foreach (const ContactIdType &id, m_aggregatedContacts) + m_changedContacts.append(id); + fetchContacts(); + + m_aggregatedContacts.clear(); } } else if (request == &m_fetchRequest) { if (m_populateProgress == Unpopulated && m_keepPopulated) { diff --git a/src/seasidecache.h b/src/seasidecache.h index 8dee688..6d643a9 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -433,6 +433,7 @@ private slots: QList m_contactsToCreate; QList m_contactsToRemove; QList m_changedContacts; + QSet m_aggregatedContacts; QList m_contactsToFetchConstituents; QList m_contactsToFetchCandidates; QList m_contactsToLinkTo;