summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/maillistmodel.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-16 17:47:48 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-16 17:47:48 +0200
commitef8a9f2f1d9f91358541b83fab63603aa3001bff (patch)
tree205a945c83a5029c7f700c0cb9c682a99fba30b2 /framework/src/domain/maillistmodel.cpp
parent899ca952964a09bf2c2304b42d2ce0d859c99c39 (diff)
downloadkube-ef8a9f2f1d9f91358541b83fab63603aa3001bff.tar.gz
kube-ef8a9f2f1d9f91358541b83fab63603aa3001bff.zip
Don't thread drafts and sent
To do this we: * Expose from the model wether or not the model is threaded * Set the relevant properties from the model on the controller (so we can switch between aggregate and non-aggregate versions) * Keep the controller in the view it belongs to. While this works it highlights a couple of issues: * Controllers are view specific and should be kept within the view. * The actions we execute in the controller are closely related to the model. The model is essentially what the user sees, and therefore what he operatees on. * Sink should perhaps expose aggregates better. We have to pass around the values from the model because the model dispatches between aggregate and non-aggregate property depending on the threaded state. Similary the controller operates on the thread or not depending on the threaded state. Perhaps it would be more useful if sink actually returned the aggregate somehow, with the regular properties. That way the controller could use the regular properties from the entity it gets (which would simply either be the aggregate or non-aggregate depending on the executed query). If the aggregate already contains all matched ids, then we would also not have to execute an additional query to get the thread again, the modification would simply be applied to all ids originally returned.
Diffstat (limited to 'framework/src/domain/maillistmodel.cpp')
-rw-r--r--framework/src/domain/maillistmodel.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/framework/src/domain/maillistmodel.cpp b/framework/src/domain/maillistmodel.cpp
index 83340f69..0f477624 100644
--- a/framework/src/domain/maillistmodel.cpp
+++ b/framework/src/domain/maillistmodel.cpp
@@ -114,9 +114,17 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const
114 case Date: 114 case Date:
115 return mail->getDate(); 115 return mail->getDate();
116 case Unread: 116 case Unread:
117 return mail->getProperty("unreadCollected").toList().contains(true); 117 if (mIsThreaded) {
118 return mail->getProperty("unreadCollected").toList().contains(true);
119 } else {
120 return mail->getUnread();
121 }
118 case Important: 122 case Important:
119 return mail->getProperty("importantCollected").toList().contains(true); 123 if (mIsThreaded) {
124 return mail->getProperty("importantCollected").toList().contains(true);
125 } else {
126 return mail->getImportant();
127 }
120 case Draft: 128 case Draft:
121 return mail->getDraft(); 129 return mail->getDraft();
122 case Sent: 130 case Sent:
@@ -133,7 +141,11 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const
133 } 141 }
134 return mail->getMimeMessage(); 142 return mail->getMimeMessage();
135 case ThreadSize: 143 case ThreadSize:
136 return mail->getProperty("count").toInt(); 144 if (mIsThreaded) {
145 return mail->getProperty("count").toInt();
146 } else {
147 return 1;
148 }
137 case Mail: 149 case Mail:
138 return QVariant::fromValue(mail); 150 return QVariant::fromValue(mail);
139 case Incomplete: 151 case Incomplete:
@@ -176,6 +188,11 @@ void MailListModel::runQuery(const Sink::Query &query)
176 setSourceModel(m_model.data()); 188 setSourceModel(m_model.data());
177} 189}
178 190
191bool MailListModel::isThreaded() const
192{
193 return mIsThreaded;
194}
195
179void MailListModel::setParentFolder(const QVariant &parentFolder) 196void MailListModel::setParentFolder(const QVariant &parentFolder)
180{ 197{
181 using namespace Sink::ApplicationDomain; 198 using namespace Sink::ApplicationDomain;
@@ -189,11 +206,33 @@ void MailListModel::setParentFolder(const QVariant &parentFolder)
189 return; 206 return;
190 } 207 }
191 mCurrentQueryItem = folder->identifier(); 208 mCurrentQueryItem = folder->identifier();
192 Sink::Query query = Sink::StandardQueries::threadLeaders(*folder); 209 if (folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::drafts) ||
210 folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::sent)) {
211 mIsThreaded = false;
212 } else {
213 mIsThreaded = true;
214 }
215 emit isThreadedChanged();
216
217 Sink::Query query = [&] {
218 if (mIsThreaded) {
219 return Sink::StandardQueries::threadLeaders(*folder);
220 } else {
221 Sink::Query query;
222 query.setId("threadleaders-unthreaded");
223 if (!folder->resourceInstanceIdentifier().isEmpty()) {
224 query.resourceFilter(folder->resourceInstanceIdentifier());
225 }
226 query.filter<Sink::ApplicationDomain::Mail::Folder>(*folder);
227 query.sort<Sink::ApplicationDomain::Mail::Date>();
228 return query;
229 }
230 }();
193 if (!folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::trash)) { 231 if (!folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::trash)) {
194 //Filter trash if this is not a trash folder 232 //Filter trash if this is not a trash folder
195 query.filter<Sink::ApplicationDomain::Mail::Trash>(false); 233 query.filter<Sink::ApplicationDomain::Mail::Trash>(false);
196 } 234 }
235
197 query.setFlags(Sink::Query::LiveQuery); 236 query.setFlags(Sink::Query::LiveQuery);
198 query.limit(100); 237 query.limit(100);
199 query.request<Mail::Subject>(); 238 query.request<Mail::Subject>();