diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-10 18:26:41 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-10 18:26:41 +0100 |
commit | c924f3118c499760f5376a6ddc9e6baf529fd0d7 (patch) | |
tree | 2d6167c0a4d19a8fb1dc1d6e99c173c1247a2162 /examples | |
parent | 5d94d9701b980d84170d0c7b860a3bc469cd8979 (diff) | |
download | sink-c924f3118c499760f5376a6ddc9e6baf529fd0d7.tar.gz sink-c924f3118c499760f5376a6ddc9e6baf529fd0d7.zip |
Simplify jobs
For some reason this also makes the synchronization to throw an error on
login failure again. Something with the job error propagation is not
quite right.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index c195cfb..be8ade5 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -433,25 +433,22 @@ public: | |||
433 | 433 | ||
434 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 434 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
435 | { | 435 | { |
436 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | ||
436 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { | 437 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { |
437 | return KAsync::start<void>([this]() { | 438 | return login(imap) |
438 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 439 | .then<QVector<Folder>>([=]() { |
439 | auto job = login(imap); | 440 | auto folderList = QSharedPointer<QVector<Folder>>::create(); |
440 | job = job.then<QVector<Folder>>([this, imap]() { | 441 | return imap->fetchFolders([folderList](const Folder &folder) { |
441 | auto folderList = QSharedPointer<QVector<Folder>>::create(); | 442 | *folderList << folder; |
442 | return imap->fetchFolders([folderList](const Folder &folder) { | 443 | }) |
443 | *folderList << folder; | 444 | .onError([](const KAsync::Error &error) { |
444 | }) | 445 | SinkWarning() << "Folder list sync failed."; |
445 | .onError([](const KAsync::Error &error) { | 446 | }) |
446 | SinkWarning() << "Folder list sync failed."; | 447 | .syncThen<QVector<Folder>>([this, folderList]() { |
447 | }) | 448 | synchronizeFolders(*folderList); |
448 | .syncThen<QVector<Folder>>([this, folderList]() { | 449 | commit(); |
449 | synchronizeFolders(*folderList); | 450 | return *folderList; |
450 | commit(); | ||
451 | return *folderList; | ||
452 | }); | ||
453 | }); | 451 | }); |
454 | return job; | ||
455 | }); | 452 | }); |
456 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { | 453 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { |
457 | //TODO | 454 | //TODO |
@@ -462,7 +459,6 @@ public: | |||
462 | //* apply the date filter to the fetch | 459 | //* apply the date filter to the fetch |
463 | //if we have no folder filter: | 460 | //if we have no folder filter: |
464 | //* fetch list of folders from server directly and sync (because we have no guarantee that the folder sync was already processed by the pipeline). | 461 | //* fetch list of folders from server directly and sync (because we have no guarantee that the folder sync was already processed by the pipeline). |
465 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | ||
466 | return login(imap) | 462 | return login(imap) |
467 | .then<void>([=] () -> KAsync::Job<void> { | 463 | .then<void>([=] () -> KAsync::Job<void> { |
468 | if (!query.ids().isEmpty()) { | 464 | if (!query.ids().isEmpty()) { |
@@ -493,9 +489,6 @@ public: | |||
493 | if ((progress % 100) == 0) { | 489 | if ((progress % 100) == 0) { |
494 | commit(); | 490 | commit(); |
495 | } | 491 | } |
496 | }) | ||
497 | .syncThen<void>([=]() { | ||
498 | commit(); | ||
499 | }); | 492 | }); |
500 | } else { | 493 | } else { |
501 | //Otherwise we sync the folder(s) | 494 | //Otherwise we sync the folder(s) |