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

Use the collection sync state attribute to store the state

This adds writing the sync state to a dedicated collection attribute
and retrieval of it as part of the collection fetch scope.
parent 23c5e97d
......@@ -60,7 +60,8 @@ set(ewsresource_SRCS
ewssettings.cpp
ewssubscribedfoldersjob.cpp
ewssubscriptionmanager.cpp
ewssubscriptionwidget.cpp)
ewssubscriptionwidget.cpp
ewssyncstateattribute.cpp)
ecm_qt_declare_logging_category(ewsresource_SRCS
HEADER ewsres_debug.h
......
......@@ -9,6 +9,7 @@
#include <QDebug>
#include <Akonadi/KMime/SpecialMailCollections>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
......@@ -43,6 +44,7 @@
#include "ewsresource_debug.h"
#include "ewssettings.h"
#include "ewssubscriptionmanager.h"
#include "ewssyncstateattribute.h"
#include "ewsupdatefolderrequest.h"
#include "ewsupdateitemrequest.h"
#include "tags/ewsglobaltagsreadjob.h"
......@@ -86,11 +88,14 @@ EwsResource::EwsResource(const QString &id)
, mInitialReconnectTimeout(InitialReconnectTimeout)
, mSettings(new EwsSettings(winIdForDialogs()))
{
AttributeFactory::registerAttribute<EwsSyncStateAttribute>();
mEwsClient.setUserAgent(mSettings->userAgent());
mEwsClient.setEnableNTLMv2(mSettings->enableNTLMv2());
changeRecorder()->fetchCollection(true);
changeRecorder()->collectionFetchScope().setAncestorRetrieval(CollectionFetchScope::Parent);
changeRecorder()->collectionFetchScope().fetchAttribute<EwsSyncStateAttribute>();
changeRecorder()->itemFetchScope().fetchFullPayload(true);
changeRecorder()->itemFetchScope().setAncestorRetrieval(ItemFetchScope::Parent);
changeRecorder()->itemFetchScope().setFetchModificationTime(false);
......@@ -1384,12 +1389,17 @@ void EwsResource::connectStatusSignals(Job *job)
QString EwsResource::getCollectionSyncState(const Akonadi::Collection &col) const
{
return mSyncState.value(col.remoteId());
auto attr = col.attribute<EwsSyncStateAttribute>();
return attr ? attr->syncState() : QString();
}
void EwsResource::saveCollectionSyncState(Akonadi::Collection &col, const QString &state)
{
mSyncState[col.remoteId()] = state;
col.addAttribute(new EwsSyncStateAttribute(state));
CollectionModifyJob *job = new CollectionModifyJob(col);
job->start();
}
AKONADI_RESOURCE_MAIN(EwsResource)
/*
SPDX-FileCopyrightText: 2020 Krzysztof Nowicki <krissn@op.pl>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ewssyncstateattribute.h"
EwsSyncStateAttribute::EwsSyncStateAttribute(const QString &syncState)
: mSyncState(syncState)
{
}
void EwsSyncStateAttribute::setSyncState(const QString &syncState)
{
mSyncState = syncState;
}
const QString &EwsSyncStateAttribute::syncState() const
{
return mSyncState;
}
QByteArray EwsSyncStateAttribute::type() const
{
static const QByteArray attrType("ewssyncstate");
return attrType;
}
Akonadi::Attribute *EwsSyncStateAttribute::clone() const
{
return new EwsSyncStateAttribute(mSyncState);
}
QByteArray EwsSyncStateAttribute::serialized() const
{
return mSyncState.toUtf8();
}
void EwsSyncStateAttribute::deserialize(const QByteArray &data)
{
mSyncState = QString::fromUtf8(data);
}
/*
SPDX-FileCopyrightText: 2020 Krzysztof Nowicki <krissn@op.pl>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <AkonadiCore/Attribute>
/**
* @brief Custom attribute to keep the EWS sync state with the collection.
*
* The EWS resource uses the SyncFolderItems operation to synchronize
* items of a collection with the server. This operation works in an
* incremental way and lets the client keep a state, so that further
* calls to the SyncFolderItems are able to retrieve changes relative
* to that state.
*/
class EwsSyncStateAttribute : public Akonadi::Attribute
{
public:
EwsSyncStateAttribute() = default;
explicit EwsSyncStateAttribute(const QString &syncState);
void setSyncState(const QString &syncState);
const QString &syncState() const;
QByteArray type() const override;
Attribute *clone() const override;
QByteArray serialized() const override;
void deserialize(const QByteArray &data) override;
private:
QString mSyncState;
};
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