diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-09 21:20:07 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-09 21:20:07 +0200 |
commit | 3a20cdfdde74716c3748fad28f6f85b07200e222 (patch) | |
tree | 18dc474130928c1439de7994269b8ff7ced143e3 /framework | |
parent | 7a3d810157e75bc16a08206bf924b326bb30dce7 (diff) | |
download | kube-3a20cdfdde74716c3748fad28f6f85b07200e222.tar.gz kube-3a20cdfdde74716c3748fad28f6f85b07200e222.zip |
A working save-as-draft action
Diffstat (limited to 'framework')
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 24 | ||||
-rw-r--r-- | framework/domain/actions/tests/sinkactiontest.cpp | 4 |
2 files changed, 7 insertions, 21 deletions
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 5dbe623c..e8f1824b 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp | |||
@@ -120,27 +120,15 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", | |||
120 | 120 | ||
121 | if (existingMail.identifier().isEmpty()) { | 121 | if (existingMail.identifier().isEmpty()) { |
122 | Sink::Query query; | 122 | Sink::Query query; |
123 | query += Sink::Query::RequestedProperties(QByteArrayList() << "name"); | 123 | //TODO replace with capability filter |
124 | query += Sink::Query::PropertyContainsFilter("specialpurpose", "drafts"); | 124 | query += Sink::Query::PropertyFilter("type", "org.kde.maildir"); |
125 | query += Sink::Query::AccountFilter(accountId); | 125 | query += Sink::Query::AccountFilter(accountId); |
126 | qWarning() << "fetching the drafts folder"; | 126 | return Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(query) |
127 | return Sink::Store::fetchAll<Sink::ApplicationDomain::Folder>(query) | 127 | .then<void, KAsync::Job<void>, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job<void> { |
128 | .then<void, QList<Sink::ApplicationDomain::Folder::Ptr>>([=](const QList<Sink::ApplicationDomain::Folder::Ptr> folders) { | 128 | Sink::ApplicationDomain::Mail mail(resource.identifier()); |
129 | qWarning() << "fetched a drafts folder" << folders.size(); | 129 | mail.setProperty("draft", true); |
130 | if (folders.isEmpty()) { | ||
131 | return KAsync::error<void>(1, "Failed to find a drafts folder."); | ||
132 | } | ||
133 | if (folders.size() > 1) { | ||
134 | qWarning() << "Found too many draft folders (taking the first): " << folders; | ||
135 | } | ||
136 | const auto folder = folders.first(); | ||
137 | Sink::ApplicationDomain::Mail mail(folder->resourceInstanceIdentifier()); | ||
138 | mail.setProperty("folder", folder->identifier()); | ||
139 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | 130 | mail.setBlobProperty("mimeMessage", message->encodedContent()); |
140 | return Sink::Store::create(mail); | 131 | return Sink::Store::create(mail); |
141 | }) | ||
142 | .then<void>([](){ | ||
143 | qWarning() << "done"; | ||
144 | }); | 132 | }); |
145 | } else { | 133 | } else { |
146 | qWarning() << "Modifying an existing mail"; | 134 | qWarning() << "Modifying an existing mail"; |
diff --git a/framework/domain/actions/tests/sinkactiontest.cpp b/framework/domain/actions/tests/sinkactiontest.cpp index 3ba9ffb9..79375503 100644 --- a/framework/domain/actions/tests/sinkactiontest.cpp +++ b/framework/domain/actions/tests/sinkactiontest.cpp | |||
@@ -39,8 +39,6 @@ private slots: | |||
39 | message->assemble(); | 39 | message->assemble(); |
40 | 40 | ||
41 | auto &&account = Test::TestAccount::registerAccount(); | 41 | auto &&account = Test::TestAccount::registerAccount(); |
42 | auto folder = account.createEntity<ApplicationDomain::Folder>(); | ||
43 | folder->setProperty("specialpurpose", QVariant::fromValue(QByteArrayList() << "drafts")); | ||
44 | 42 | ||
45 | Kube::Context context; | 43 | Kube::Context context; |
46 | context.setProperty("message", QVariant::fromValue(message)); | 44 | context.setProperty("message", QVariant::fromValue(message)); |
@@ -52,7 +50,7 @@ private slots: | |||
52 | auto mails = account.entities<Sink::ApplicationDomain::Mail>(); | 50 | auto mails = account.entities<Sink::ApplicationDomain::Mail>(); |
53 | QCOMPARE(mails.size(), 1); | 51 | QCOMPARE(mails.size(), 1); |
54 | auto mail = mails.first(); | 52 | auto mail = mails.first(); |
55 | QCOMPARE(mail->getProperty("folder").toByteArray(), folder->identifier()); | 53 | QVERIFY(mail->getProperty("draft").toBool()); |
56 | } | 54 | } |
57 | }; | 55 | }; |
58 | 56 | ||