Commit fe4c096c authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Fix conflict error bug when changing the same item

parent bec28a94
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <AkonadiCore/AttributeFactory> #include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/CollectionColorAttribute> #include <AkonadiCore/CollectionColorAttribute>
#include <AkonadiCore/CollectionModifyJob> #include <AkonadiCore/CollectionModifyJob>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemModifyJob>
#include <KCalendarCore/ICalFormat> #include <KCalendarCore/ICalFormat>
#include <KCalendarCore/MemoryCalendar> #include <KCalendarCore/MemoryCalendar>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -237,9 +239,12 @@ void CalendarTaskBaseHandler::itemChanged(const Akonadi::Item &item, ...@@ -237,9 +239,12 @@ void CalendarTaskBaseHandler::itemChanged(const Akonadi::Item &item,
return; return;
} }
// Using ItemModifyJob + changeProcessed() instead of changeCommitted to handle conflict error - ItemSync modifies local item payload
Item newItem(item); Item newItem(item);
newItem.setPayload<Incidence::Ptr>(incidence); newItem.setPayload<Incidence::Ptr>(incidence);
mResource->changeCommitted(newItem); Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(newItem);
modifyJob->disableRevisionCheck();
mResource->changeProcessed();
updateLocalCalendar(item.payload<Incidence::Ptr>()); updateLocalCalendar(item.payload<Incidence::Ptr>());
} }
......
...@@ -241,9 +241,12 @@ void ContactHandler::itemChanged(const Akonadi::Item &item, ...@@ -241,9 +241,12 @@ void ContactHandler::itemChanged(const Akonadi::Item &item,
return; return;
} }
// Using ItemModifyJob + changeProcessed() instead of changeCommitted to handle conflict error - ItemSync modifies local item payload
Item newItem(item); Item newItem(item);
newItem.setPayload<KContacts::Addressee>(contact); newItem.setPayload<KContacts::Addressee>(contact);
mResource->changeCommitted(newItem); Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(newItem);
modifyJob->disableRevisionCheck();
mResource->changeProcessed();
updateLocalContact(item.payload<KContacts::Addressee>()); updateLocalContact(item.payload<KContacts::Addressee>());
} }
......
...@@ -98,6 +98,25 @@ void EteSyncClientState::refreshToken() ...@@ -98,6 +98,25 @@ void EteSyncClientState::refreshToken()
tokenRefreshed(); tokenRefreshed();
} }
void EteSyncClientState::refreshUserInfo()
{
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
mUserInfo = etesync_user_info_manager_fetch(userInfoManager.get(), mUsername);
if (!mUserInfo) {
qCWarning(ETESYNC_LOG) << "initUserInfo() - User info obtained from server is NULL";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
return;
}
EteSyncCryptoManagerPtr userInfoCryptoManager = etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived);
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(mUserInfo.get(), userInfoCryptoManager.get()));
if (!mKeypair) {
qCDebug(ETESYNC_LOG) << "Empty keypair";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
return;
}
qCDebug(ETESYNC_LOG) << "Received keypair";
}
bool EteSyncClientState::initUserInfo() bool EteSyncClientState::initUserInfo()
{ {
mJournalManager = EteSyncJournalManagerPtr(etesync_journal_manager_new(mClient.get())); mJournalManager = EteSyncJournalManagerPtr(etesync_journal_manager_new(mClient.get()));
......
...@@ -35,6 +35,7 @@ public: ...@@ -35,6 +35,7 @@ public:
void initAccount(const QString &encryptionPassword); void initAccount(const QString &encryptionPassword);
void saveSettings(); void saveSettings();
void invalidateToken(); void invalidateToken();
void refreshUserInfo();
EteSync *client() const EteSync *client() const
{ {
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <AkonadiCore/CollectionFetchScope> #include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/CollectionModifyJob> #include <AkonadiCore/CollectionModifyJob>
#include <AkonadiCore/EntityDisplayAttribute> #include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope> #include <AkonadiCore/ItemFetchScope>
#include <KCalendarCore/Event> #include <KCalendarCore/Event>
#include <KCalendarCore/Todo> #include <KCalendarCore/Todo>
...@@ -118,6 +117,7 @@ void EteSyncResource::retrieveCollections() ...@@ -118,6 +117,7 @@ void EteSyncResource::retrieveCollections()
setCollectionStreamingEnabled(true); setCollectionStreamingEnabled(true);
mJournalsCache.clear(); mJournalsCache.clear();
mClientState->refreshUserInfo();
auto job = new JournalsFetchJob(mClientState->client(), this); auto job = new JournalsFetchJob(mClientState->client(), this);
connect(job, &JournalsFetchJob::finished, this, &EteSyncResource::slotCollectionsRetrieved); connect(job, &JournalsFetchJob::finished, this, &EteSyncResource::slotCollectionsRetrieved);
......
...@@ -64,7 +64,6 @@ protected: ...@@ -64,7 +64,6 @@ protected:
Collection createRootCollection(); Collection createRootCollection();
void initialiseDirectory(const QString &path) const; void initialiseDirectory(const QString &path) const;
QString baseDirectoryPath() const; QString baseDirectoryPath() const;
bool handleTokenError(); bool handleTokenError();
......
Markdown is supported
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