Skip to content

Commit

Permalink
[buteo-sync-plugins-social] If Google contact sync fails, request ful…
Browse files Browse the repository at this point in the history
…l contact listing on next sync. JB#53422

This ensures the plugin cannot get into a loop where it continually
fails because of some sync conflict with the server, and thus can
never be synced. Doing a full contact listing on the next sync will
ensure we are up-to-date with the server's contacts.
  • Loading branch information
blammit committed Mar 11, 2021
1 parent 5499f75 commit d201eac
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/google/google-contacts/googletwowaycontactsyncadaptor.cpp
Expand Up @@ -188,6 +188,33 @@ void GoogleContactSqliteSyncAdaptor::syncFinishedSuccessfully()
void GoogleContactSqliteSyncAdaptor::syncFinishedWithError()
{
SOCIALD_LOG_ERROR("Sync finished with error");

if (q->m_collection.id().isNull()) {
return;
}

// If sync fails, clear the sync token and date for the collection, so that the next sync
// requests a full contact listing, to ensure we are up-to-date with the server.

q->m_collection.setExtendedMetaData(CollectionKeySyncToken, QString());
q->m_collection.setExtendedMetaData(CollectionKeySyncTokenDate, QString());

QHash<QContactCollection*, QList<QContact>* > modifiedCollections;
QList<QContact> emptyContacts;
modifiedCollections.insert(&q->m_collection, &emptyContacts);

QtContactsSqliteExtensions::ContactManagerEngine *cme = QtContactsSqliteExtensions::contactManagerEngine(*q->m_contactManager);
QContactManager::Error error = QContactManager::NoError;

if (!cme->storeChanges(nullptr,
&modifiedCollections,
QList<QContactCollectionId>(),
QtContactsSqliteExtensions::ContactManagerEngine::PreserveLocalChanges,
true,
&error)) {
SOCIALD_LOG_ERROR("Failed to clear sync token for account:" << q->m_accountId
<< "due to error:" << error);
}
}

//-------------------------------------
Expand Down Expand Up @@ -1110,12 +1137,14 @@ void GoogleTwoWayContactSyncAdaptor::purgeAccount(int pid)

void GoogleTwoWayContactSyncAdaptor::finalize(int accountId)
{
if (syncAborted()|| status() == SocialNetworkSyncAdaptor::Error) {
m_sqliteSync->syncFinishedWithError();
return;
}

if (accountId != m_accountId
|| m_accessToken.isEmpty()
|| syncAborted()
|| status() == SocialNetworkSyncAdaptor::Error) {
|| m_accessToken.isEmpty()) {
// account failure occurred before sync process was started,
// or other error occurred during sync.
// in this case we have nothing left to do except cleanup.
return;
}
Expand Down

0 comments on commit d201eac

Please sign in to comment.