Skip to content

Commit

Permalink
Merge branch 'sequence' into 'master'
Browse files Browse the repository at this point in the history
[buteo-sync-plugin-caldav] Retrieve full event after PUT when the etag is missing.

See merge request mer-core/buteo-sync-plugin-caldav!70
  • Loading branch information
chriadam committed Jun 10, 2020
2 parents f1735ad + 6732484 commit cec6302
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
32 changes: 15 additions & 17 deletions src/notebooksyncagent.cpp
Expand Up @@ -632,8 +632,7 @@ void NotebookSyncAgent::finalizeSendingLocalChanges()
Report *report = new Report(mNetworkManager, mSettings);
mRequests.insert(report);
connect(report, SIGNAL(finished()), this, SLOT(additionalReportRequestFinished()));
report->multiGetEtags(mRemoteCalendarPath, mSentUids.keys());
return;
report->multiGetEvents(mRemoteCalendarPath, mSentUids.keys());
} else {
emitFinished(Buteo::SyncResults::NO_ERROR);
}
Expand All @@ -646,30 +645,22 @@ void NotebookSyncAgent::additionalReportRequestFinished()
// The server did not originally respond with the update ETAG values after
// our initial PUT/UPDATE so we had to do an addition report request.
// This response will contain the new ETAG values for any resource we
// upsynced (ie, a local modification/addition).
// upsynced (ie, a local modification/addition) and also the incidence
// as it may have been modified by the server.

Report *report = qobject_cast<Report*>(sender());
mRequests.remove(report);
report->deleteLater();

if (report->errorCode() == Buteo::SyncResults::NO_ERROR) {
LOG_DEBUG("Additional report request finished: received:"
<< report->receivedCalendarResources().length() << "iCal blobs containing a total of"
<< report->receivedCalendarResources().count() << "incidences");
for (QList<Reader::CalendarResource>::ConstIterator
it = report->receivedCalendarResources().constBegin();
it != report->receivedCalendarResources().constEnd(); ++it) {
if (mSentUids.contains(it->href)) {
updateHrefETag(mSentUids.take(it->href), it->href, it->etag);
}
}
LOG_DEBUG("Remains" << mSentUids.count() << "uris not updated.");
mReceivedCalendarResources += report->receivedCalendarResources();
emitFinished(Buteo::SyncResults::NO_ERROR);
return;
} else {
LOG_WARNING("Additional report request finished with error, aborting sync of notebook:" << mRemoteCalendarPath);
emitFinished(report->errorCode(), report->errorString());
}

LOG_WARNING("Additional report request finished with error, aborting sync of notebook:" << mRemoteCalendarPath);
emitFinished(report->errorCode(), report->errorString());
}

bool NotebookSyncAgent::applyRemoteChanges()
Expand Down Expand Up @@ -1020,7 +1011,14 @@ void NotebookSyncAgent::updateIncidence(KCalCore::Incidence::Ptr incidence,
}

storedIncidence->endUpdates();
storedIncidence->setLastModified(incidence->lastModified());
// Avoid spurious detections of modified incidences
// by ensuring that the received last modification date time
// is previous to the sync date time.
if (incidence->lastModified() < mNotebookSyncedDateTime) {
storedIncidence->setLastModified(incidence->lastModified());
} else {
storedIncidence->setLastModified(mNotebookSyncedDateTime.addSecs(-2));
}
}
incidence->setUid(storedIncidence->uid());
}
Expand Down
18 changes: 1 addition & 17 deletions src/report.cpp
Expand Up @@ -109,30 +109,14 @@ void Report::sendCalendarQuery(const QString &remoteCalendarPath,
}

void Report::multiGetEvents(const QString &remoteCalendarPath, const QStringList &eventHrefList)
{
FUNCTION_CALL_TRACE;
sendMultiQuery(remoteCalendarPath, eventHrefList, true);
}

void Report::multiGetEtags(const QString &remoteCalendarPath, const QStringList &eventHrefList)
{
FUNCTION_CALL_TRACE;
sendMultiQuery(remoteCalendarPath, eventHrefList, false);
}

void Report::sendMultiQuery(const QString &remoteCalendarPath, const QStringList &eventHrefList, bool getCalendarData)
{
FUNCTION_CALL_TRACE;
if (eventHrefList.isEmpty()) {
return;
}

QByteArray requestData = "<c:calendar-multiget xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\">" \
"<d:prop><d:getetag />";
if (getCalendarData) {
requestData += "<c:calendar-data />";
}
requestData += "</d:prop>";
"<d:prop><d:getetag /><c:calendar-data /></d:prop>";
for (const QString &eventHref : eventHrefList) {
requestData.append("<d:href>");
requestData.append(eventHref.toUtf8());
Expand Down
4 changes: 0 additions & 4 deletions src/report.h
Expand Up @@ -47,7 +47,6 @@ class Report : public Request
const QDateTime &fromDateTime = QDateTime(),
const QDateTime &toDateTime = QDateTime());
void multiGetEvents(const QString &remoteCalendarPath, const QStringList &eventHrefList);
void multiGetEtags(const QString &remoteCalendarPath, const QStringList &eventHrefList);

const QList<Reader::CalendarResource>& receivedCalendarResources() const;

Expand All @@ -60,9 +59,6 @@ private Q_SLOTS:
const QDateTime &fromDateTime,
const QDateTime &toDateTime,
bool getCalendarData);
void sendMultiQuery(const QString &remoteCalendarPath,
const QStringList &uris,
bool getCalendarData);
QString mRemoteCalendarPath;
QList<Reader::CalendarResource> mReceivedResources;
};
Expand Down

0 comments on commit cec6302

Please sign in to comment.