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

Fix bug related to changing item after addition

parent 2af86bd0
......@@ -132,7 +132,8 @@ void CalendarTaskBaseHandler::itemAdded(const Akonadi::Item &item,
const Akonadi::Collection &collection)
{
KCalendarCore::Calendar::Ptr calendar(new MemoryCalendar(QTimeZone::utc()));
calendar->addIncidence(item.payload<Incidence::Ptr>());
const auto incidence = item.payload<Incidence::Ptr>();
calendar->addIncidence(incidence);
KCalendarCore::ICalFormat format;
const QString journalUid = collection.remoteId();
......@@ -146,7 +147,10 @@ void CalendarTaskBaseHandler::itemAdded(const Akonadi::Item &item,
return;
}
mResource->changeCommitted(item);
Item newItem(item);
newItem.setRemoteId(incidence->uid());
newItem.setPayload<Incidence::Ptr>(incidence);
mResource->changeCommitted(newItem);
updateLocalCalendar(item.payload<Incidence::Ptr>());
}
......@@ -157,7 +161,8 @@ void CalendarTaskBaseHandler::itemChanged(const Akonadi::Item &item,
Collection collection = item.parentCollection();
KCalendarCore::Calendar::Ptr calendar(new MemoryCalendar(QTimeZone::utc()));
calendar->addIncidence(item.payload<Incidence::Ptr>());
const auto incidence = item.payload<Incidence::Ptr>();
calendar->addIncidence(incidence);
KCalendarCore::ICalFormat format;
const QString journalUid = collection.remoteId();
......@@ -171,7 +176,9 @@ void CalendarTaskBaseHandler::itemChanged(const Akonadi::Item &item,
return;
}
mResource->changeCommitted(item);
Item newItem(item);
newItem.setPayload<Incidence::Ptr>(incidence);
mResource->changeCommitted(newItem);
updateLocalCalendar(item.payload<Incidence::Ptr>());
}
......@@ -244,7 +251,9 @@ void CalendarTaskBaseHandler::collectionChanged(const Akonadi::Collection &colle
return;
}
mResource->changeCommitted(collection);
Collection newCollection(collection);
mResource->setupCollection(newCollection, journal.get());
mResource->changeCommitted(newCollection);
}
void CalendarTaskBaseHandler::collectionRemoved(const Akonadi::Collection &collection)
......
......@@ -141,7 +141,8 @@ void ContactHandler::itemAdded(const Akonadi::Item &item,
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
KContacts::VCardConverter converter;
QByteArray content = converter.createVCard(item.payload<KContacts::Addressee>());
const auto contact = item.payload<KContacts::Addressee>();
QByteArray content = converter.createVCard(contact);
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_ADD), QString::fromUtf8(content));
......@@ -149,7 +150,10 @@ void ContactHandler::itemAdded(const Akonadi::Item &item,
return;
}
mResource->changeCommitted(item);
Item newItem(item);
newItem.setRemoteId(contact.uid());
newItem.setPayload<KContacts::Addressee>(contact);
mResource->changeCommitted(newItem);
updateLocalContact(item.payload<KContacts::Addressee>());
}
......@@ -165,7 +169,8 @@ void ContactHandler::itemChanged(const Akonadi::Item &item,
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
KContacts::VCardConverter converter;
QByteArray content = converter.createVCard(item.payload<KContacts::Addressee>());
const auto contact = item.payload<KContacts::Addressee>();
QByteArray content = converter.createVCard(contact);
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_CHANGE), QString::fromUtf8(content));
......@@ -173,7 +178,9 @@ void ContactHandler::itemChanged(const Akonadi::Item &item,
return;
}
mResource->changeCommitted(item);
Item newItem(item);
newItem.setPayload<KContacts::Addressee>(contact);
mResource->changeCommitted(newItem);
updateLocalContact(item.payload<KContacts::Addressee>());
}
......@@ -237,7 +244,9 @@ void ContactHandler::collectionChanged(const Akonadi::Collection &collection)
return;
}
mResource->changeCommitted(collection);
Collection newCollection(collection);
mResource->setupCollection(newCollection, journal.get());
mResource->changeCommitted(newCollection);
}
void ContactHandler::collectionRemoved(const Akonadi::Collection &collection)
......
......@@ -213,6 +213,7 @@ void EteSyncResource::setupCollection(Collection &collection, EteSyncJournal *jo
if (etesync_journal_is_read_only(journal)) {
collection.setRights(Collection::ReadOnly);
}
collection.setRemoteId(journalUid);
collection.setName(displayName);
collection.setContentMimeTypes(mimeTypes);
......
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