From 7129af7b55dd13c8caa359f7cda9642bfab533b4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 11 Jan 2017 14:58:20 +0100 Subject: Fetch incomplete mails automatically. --- framework/domain/maillistmodel.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'framework/domain/maillistmodel.cpp') diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index 0e76e0a8..207128b7 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp @@ -125,9 +125,23 @@ bool MailListModel::lessThan(const QModelIndex &left, const QModelIndex &right) void MailListModel::runQuery(const Sink::Query &query) { m_model = Sink::Store::loadModel(query); + QObject::connect(m_model.data(), &QAbstractItemModel::rowsInserted, this, &MailListModel::onRowsInserted); setSourceModel(m_model.data()); } +void MailListModel::onRowsInserted(const QModelIndex &parent, int begin, int end) +{ + if (mFetchMails) { + for (int row = begin; row <= end; row++) { + auto mail = sourceModel()->index(row, 0, parent).data(Sink::Store::DomainObjectRole).value(); + if (mail && !mail->getFullPayloadAvailable()) { + qWarning() << "Fetching mail: " << mail->identifier(); + Sink::Store::synchronize(Sink::SyncScope{*mail}).exec(); + } + } + } +} + void MailListModel::setParentFolder(const QVariant &parentFolder) { using namespace Sink::ApplicationDomain; @@ -150,6 +164,7 @@ void MailListModel::setParentFolder(const QVariant &parentFolder) query.request(); query.request(); query.request(); + mFetchMails = false; qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); runQuery(query); } @@ -179,6 +194,8 @@ void MailListModel::setMail(const QVariant &variant) query.request(); query.request(); query.request(); + query.request(); + mFetchMails = true; qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); runQuery(query); } -- cgit v1.2.3