From 9f548500214925cd0075fd2434afd116618d7196 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 8 Feb 2017 23:40:49 +0100 Subject: Fetch the mail when trying to access the content. That way we can try to only fetch the content for messages that are actually shown. --- framework/domain/maillistmodel.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'framework/domain/maillistmodel.cpp') diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index c33d8b67..6fe80092 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp @@ -74,6 +74,14 @@ static QString join(const QList &contact return list.join(", "); } +void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail) +{ + if (mail && !mail->getFullPayloadAvailable()) { + qWarning() << "Fetching mail: " << mail->identifier() << mail->getSubject(); + Sink::Store::synchronize(Sink::SyncScope{*mail}).exec(); + } +} + QVariant MailListModel::data(const QModelIndex &idx, int role) const { auto srcIdx = mapToSource(idx); @@ -106,6 +114,9 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const case DomainObject: return QVariant::fromValue(mail); case MimeMessage: + if (mFetchMails) { + fetchMail(mail); + } return mail->getMimeMessage(); case ThreadSize: return mail->getProperty("count").toInt(); @@ -125,23 +136,9 @@ 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 && sourceModel()) { - 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; -- cgit v1.2.3