From 3a20cdfdde74716c3748fad28f6f85b07200e222 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 9 May 2016 21:20:07 +0200 Subject: A working save-as-draft action --- framework/domain/actions/sinkactions.cpp | 24 ++++++----------------- framework/domain/actions/tests/sinkactiontest.cpp | 4 +--- 2 files changed, 7 insertions(+), 21 deletions(-) (limited to 'framework') 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", if (existingMail.identifier().isEmpty()) { Sink::Query query; - query += Sink::Query::RequestedProperties(QByteArrayList() << "name"); - query += Sink::Query::PropertyContainsFilter("specialpurpose", "drafts"); + //TODO replace with capability filter + query += Sink::Query::PropertyFilter("type", "org.kde.maildir"); query += Sink::Query::AccountFilter(accountId); - qWarning() << "fetching the drafts folder"; - return Sink::Store::fetchAll(query) - .then>([=](const QList folders) { - qWarning() << "fetched a drafts folder" << folders.size(); - if (folders.isEmpty()) { - return KAsync::error(1, "Failed to find a drafts folder."); - } - if (folders.size() > 1) { - qWarning() << "Found too many draft folders (taking the first): " << folders; - } - const auto folder = folders.first(); - Sink::ApplicationDomain::Mail mail(folder->resourceInstanceIdentifier()); - mail.setProperty("folder", folder->identifier()); + return Sink::Store::fetchOne(query) + .then, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { + Sink::ApplicationDomain::Mail mail(resource.identifier()); + mail.setProperty("draft", true); mail.setBlobProperty("mimeMessage", message->encodedContent()); return Sink::Store::create(mail); - }) - .then([](){ - qWarning() << "done"; }); } else { 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: message->assemble(); auto &&account = Test::TestAccount::registerAccount(); - auto folder = account.createEntity(); - folder->setProperty("specialpurpose", QVariant::fromValue(QByteArrayList() << "drafts")); Kube::Context context; context.setProperty("message", QVariant::fromValue(message)); @@ -52,7 +50,7 @@ private slots: auto mails = account.entities(); QCOMPARE(mails.size(), 1); auto mail = mails.first(); - QCOMPARE(mail->getProperty("folder").toByteArray(), folder->identifier()); + QVERIFY(mail->getProperty("draft").toBool()); } }; -- cgit v1.2.3