diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 23:37:37 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 23:37:37 +0100 |
commit | 2b9bd7855843b1b58f0b124b0c92b9a8c601e2ba (patch) | |
tree | c95e47d7e5a45b0ebadd30ad2abe9bf4fcc95af4 /examples | |
parent | a48edff7a21ef6426baa1cc6eca501930cb35645 (diff) | |
download | sink-2b9bd7855843b1b58f0b124b0c92b9a8c601e2ba.tar.gz sink-2b9bd7855843b1b58f0b124b0c92b9a8c601e2ba.zip |
Simplification
Diffstat (limited to 'examples')
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index a4622f3..a49d62b 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -81,12 +81,28 @@ public: | |||
81 | return KAsync::error<void>(1, "Failed to send the message."); | 81 | return KAsync::error<void>(1, "Failed to send the message."); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | return KAsync::null<void>(); | 84 | return KAsync::start<void>([=] { |
85 | SinkLog() << "Sent mail, and triggering move to sent mail folder: " << mail.identifier(); | ||
86 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, mail.identifier(), mail.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
87 | modifiedMail.setSent(true); | ||
88 | |||
89 | auto resource = Store::readOne<ApplicationDomain::SinkResource>(Query{}.filter(mResourceInstanceIdentifier).request<ApplicationDomain::SinkResource::Account>()); | ||
90 | //Then copy the mail to the target resource | ||
91 | Query query; | ||
92 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::sent); | ||
93 | query.filter<ApplicationDomain::SinkResource::Account>(resource.getAccount()); | ||
94 | return Store::fetchOne<ApplicationDomain::SinkResource>(query) | ||
95 | .then([this, modifiedMail](const ApplicationDomain::SinkResource &resource) { | ||
96 | //First modify the mail to have the sent property set to true | ||
97 | modify(modifiedMail, resource.identifier(), true); | ||
98 | return KAsync::null<void>(); | ||
99 | }); | ||
100 | }); | ||
85 | } | 101 | } |
86 | 102 | ||
87 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 103 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
88 | { | 104 | { |
89 | return KAsync::start<void>([this](KAsync::Future<void> future) { | 105 | return KAsync::start<void>([this]() { |
90 | QList<ApplicationDomain::Mail> toSend; | 106 | QList<ApplicationDomain::Mail> toSend; |
91 | SinkLog() << "Looking for mails to send."; | 107 | SinkLog() << "Looking for mails to send."; |
92 | store().readAll<ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) -> bool { | 108 | store().readAll<ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) -> bool { |
@@ -99,29 +115,9 @@ public: | |||
99 | SinkLog() << "Found " << toSend.size() << " mails to send"; | 115 | SinkLog() << "Found " << toSend.size() << " mails to send"; |
100 | auto job = KAsync::null<void>(); | 116 | auto job = KAsync::null<void>(); |
101 | for (const auto &m : toSend) { | 117 | for (const auto &m : toSend) { |
102 | job = job.then(send(m, mSettings)) | 118 | job = job.then(send(m, mSettings)); |
103 | .then<void>([this, m] { | ||
104 | SinkLog() << "Sent mail, and triggering move to sent mail folder: " << m.identifier(); | ||
105 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, m.identifier(), m.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
106 | modifiedMail.setSent(true); | ||
107 | |||
108 | auto resource = Store::readOne<ApplicationDomain::SinkResource>(Query{}.filter(mResourceInstanceIdentifier).request<ApplicationDomain::SinkResource::Account>()); | ||
109 | //Then copy the mail to the target resource | ||
110 | Query query; | ||
111 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::sent); | ||
112 | query.filter<ApplicationDomain::SinkResource::Account>(resource.getAccount()); | ||
113 | return Store::fetchOne<ApplicationDomain::SinkResource>(query) | ||
114 | .then<void, ApplicationDomain::SinkResource>([this, modifiedMail](const ApplicationDomain::SinkResource &resource) -> KAsync::Job<void> { | ||
115 | //First modify the mail to have the sent property set to true | ||
116 | modify(modifiedMail, resource.identifier(), true); | ||
117 | return KAsync::null<void>(); | ||
118 | }); | ||
119 | }); | ||
120 | } | 119 | } |
121 | job = job.then([&future](const KAsync::Error &) { | 120 | return job; |
122 | future.setFinished(); | ||
123 | }); | ||
124 | job.exec(); | ||
125 | }); | 121 | }); |
126 | } | 122 | } |
127 | 123 | ||