diff options
-rw-r--r-- | common/synchronizer.cpp | 14 | ||||
-rw-r--r-- | common/synchronizer.h | 5 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 38 |
3 files changed, 53 insertions, 4 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index b147615..fcdb5b8 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -252,15 +252,21 @@ void Synchronizer::modify(const DomainType &entity, const QByteArray &newResourc | |||
252 | 252 | ||
253 | QList<Synchronizer::SyncRequest> Synchronizer::getSyncRequests(const Sink::QueryBase &query) | 253 | QList<Synchronizer::SyncRequest> Synchronizer::getSyncRequests(const Sink::QueryBase &query) |
254 | { | 254 | { |
255 | QList<Synchronizer::SyncRequest> list; | 255 | return QList<Synchronizer::SyncRequest>() << Synchronizer::SyncRequest{query, "sync"}; |
256 | list << Synchronizer::SyncRequest{query, "sync"}; | 256 | } |
257 | return list; | 257 | |
258 | void Synchronizer::mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue) | ||
259 | { | ||
260 | mSyncRequestQueue << request; | ||
258 | } | 261 | } |
259 | 262 | ||
260 | void Synchronizer::synchronize(const Sink::QueryBase &query) | 263 | void Synchronizer::synchronize(const Sink::QueryBase &query) |
261 | { | 264 | { |
262 | SinkTraceCtx(mLogCtx) << "Synchronizing"; | 265 | SinkTraceCtx(mLogCtx) << "Synchronizing"; |
263 | mSyncRequestQueue << getSyncRequests(query); | 266 | auto newRequests = getSyncRequests(query); |
267 | for (const auto &request: newRequests) { | ||
268 | mergeIntoQueue(request, mSyncRequestQueue); | ||
269 | } | ||
264 | processSyncQueue().exec(); | 270 | processSyncQueue().exec(); |
265 | } | 271 | } |
266 | 272 | ||
diff --git a/common/synchronizer.h b/common/synchronizer.h index 120a8a5..af042cb 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -175,6 +175,11 @@ protected: | |||
175 | */ | 175 | */ |
176 | virtual QList<Synchronizer::SyncRequest> getSyncRequests(const Sink::QueryBase &query); | 176 | virtual QList<Synchronizer::SyncRequest> getSyncRequests(const Sink::QueryBase &query); |
177 | 177 | ||
178 | /** | ||
179 | * This allows the synchronizer to merge new requests with existing requests in the queue. | ||
180 | */ | ||
181 | virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); | ||
182 | |||
178 | protected: | 183 | protected: |
179 | Sink::Log::Context mLogCtx; | 184 | Sink::Log::Context mLogCtx; |
180 | private: | 185 | private: |
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 09f57d5..fff4dc7 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -393,6 +393,44 @@ public: | |||
393 | return list; | 393 | return list; |
394 | } | 394 | } |
395 | 395 | ||
396 | QByteArray getFolderFromLocalId(const QByteArray &id) | ||
397 | { | ||
398 | auto mailRemoteId = syncStore().resolveLocalId(ApplicationDomain::getTypeName<ApplicationDomain::Mail>(), id); | ||
399 | return folderIdFromMailRid(mailRemoteId); | ||
400 | } | ||
401 | |||
402 | void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue) Q_DECL_OVERRIDE | ||
403 | { | ||
404 | auto isIndividualMailSync = [](const Synchronizer::SyncRequest &request) { | ||
405 | if (request.requestType == SyncRequest::Synchronization) { | ||
406 | const auto query = request.query; | ||
407 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { | ||
408 | return !query.ids().isEmpty(); | ||
409 | } | ||
410 | } | ||
411 | return false; | ||
412 | |||
413 | }; | ||
414 | |||
415 | if (isIndividualMailSync(request)) { | ||
416 | auto newId = request.query.ids().first(); | ||
417 | auto requestFolder = getFolderFromLocalId(newId); | ||
418 | for (auto &r : queue) { | ||
419 | if (isIndividualMailSync(r)) { | ||
420 | auto queueFolder = getFolderFromLocalId(r.query.ids().first()); | ||
421 | if (requestFolder == queueFolder) { | ||
422 | //Merge | ||
423 | r.query.filter(newId); | ||
424 | SinkTrace() << "Merging request " << request.query; | ||
425 | SinkTrace() << " to " << r.query; | ||
426 | return; | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | } | ||
431 | queue << request; | ||
432 | } | ||
433 | |||
396 | KAsync::Job<void> login(QSharedPointer<ImapServerProxy> imap) | 434 | KAsync::Job<void> login(QSharedPointer<ImapServerProxy> imap) |
397 | { | 435 | { |
398 | SinkTrace() << "Connecting to:" << mServer << mPort; | 436 | SinkTrace() << "Connecting to:" << mServer << mPort; |