Commit 23c5e97d authored by Krzysztof Nowicki's avatar Krzysztof Nowicki Committed by Laurent Montel
Browse files

Factor out collection sync state handing into dedicated methods

This is a preparatory change for moving the collection sync state from
the resource config file into the Akonadi database itself.
parent 8316db61
......@@ -319,7 +319,7 @@ void EwsResource::connectionError()
void EwsResource::retrieveItems(const Collection &collection)
{
QString rid = collection.remoteId();
auto job = new EwsFetchItemsJob(collection, mEwsClient, mSyncState.value(rid), mItemsToCheck.value(rid), mTagStore, this);
auto job = new EwsFetchItemsJob(collection, mEwsClient, getCollectionSyncState(collection), mItemsToCheck.value(rid), mTagStore, this);
job->setQueuedUpdates(mQueuedUpdates.value(collection.remoteId()));
mQueuedUpdates.remove(collection.remoteId());
connect(job, &EwsFetchItemsJob::result, this, &EwsResource::itemFetchJobFinished);
......@@ -442,13 +442,15 @@ void EwsResource::itemFetchJobFinished(KJob *job)
cancelTask(i18nc("@info:status", "Failed to retrieve items - internal error"));
return;
}
auto col = fetchJob->collection();
if (job->error()) {
qCWarningNC(EWSRES_LOG) << QStringLiteral("Item fetch error:") << job->errorString();
if (mSyncState.contains(fetchJob->collection().remoteId())) {
const auto syncState = getCollectionSyncState(fetchJob->collection());
if (!syncState.isEmpty()) {
qCDebugNC(EWSRES_LOG) << QStringLiteral("Retrying with empty state.");
// Retry with a clear sync state.
mSyncState.remove(fetchJob->collection().remoteId());
retrieveItems(fetchJob->collection());
saveCollectionSyncState(col, QString());
retrieveItems(col);
} else {
qCDebugNC(EWSRES_LOG) << QStringLiteral("Clean sync failed.");
// No more hope
......@@ -456,7 +458,7 @@ void EwsResource::itemFetchJobFinished(KJob *job)
return;
}
} else {
mSyncState[fetchJob->collection().remoteId()] = fetchJob->syncState();
saveCollectionSyncState(col, fetchJob->syncState());
itemsRetrievedIncremental(fetchJob->changedItems(), fetchJob->deletedItems());
}
saveState();
......@@ -1380,4 +1382,14 @@ void EwsResource::connectStatusSignals(Job *job)
});
}
QString EwsResource::getCollectionSyncState(const Akonadi::Collection &col) const
{
return mSyncState.value(col.remoteId());
}
void EwsResource::saveCollectionSyncState(Akonadi::Collection &col, const QString &state)
{
mSyncState[col.remoteId()] = state;
}
AKONADI_RESOURCE_MAIN(EwsResource)
......@@ -141,6 +141,9 @@ private:
void reauthNotificationDismissed(bool accepted);
void reauthenticate();
QString getCollectionSyncState(const Akonadi::Collection &col) const;
void saveCollectionSyncState(Akonadi::Collection &col, const QString &state);
template<class Job>
void connectStatusSignals(Job *job);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment