summaryrefslogtreecommitdiffstats
path: root/common/domain/mail.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r--common/domain/mail.cpp52
1 files changed, 31 insertions, 21 deletions
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 2b6eb84..1b46e28 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -45,25 +45,31 @@ static QMutex sMutex;
45using namespace Sink; 45using namespace Sink;
46using namespace Sink::ApplicationDomain; 46using namespace Sink::ApplicationDomain;
47 47
48void TypeImplementation<Mail>::configureIndex(TypeIndex &index)
49{
50 index.addProperty<QByteArray>(Mail::Uid::name);
51 index.addProperty<QByteArray>(Mail::Sender::name);
52 index.addProperty<QByteArray>(Mail::SenderName::name);
53 /* index->addProperty<QString>(Mail::Subject::name); */
54 /* index->addFulltextProperty<QString>(Mail::Subject::name); */
55 index.addProperty<QDateTime>(Mail::Date::name);
56 index.addProperty<QByteArray>(Mail::Folder::name);
57 index.addPropertyWithSorting<QByteArray, QDateTime>(Mail::Folder::name, Mail::Date::name);
58 index.addProperty<QByteArray>(Mail::MessageId::name);
59 index.addProperty<QByteArray>(Mail::ParentMessageId::name);
60
61 index.addProperty<Mail::MessageId>();
62 index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>();
63 index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>();
64}
65
48static TypeIndex &getIndex() 66static TypeIndex &getIndex()
49{ 67{
50 QMutexLocker locker(&sMutex); 68 QMutexLocker locker(&sMutex);
51 static TypeIndex *index = 0; 69 static TypeIndex *index = 0;
52 if (!index) { 70 if (!index) {
53 index = new TypeIndex("mail"); 71 index = new TypeIndex("mail");
54 index->addProperty<QByteArray>(Mail::Uid::name); 72 TypeImplementation<Mail>::configureIndex(*index);
55 index->addProperty<QByteArray>(Mail::Sender::name);
56 index->addProperty<QByteArray>(Mail::SenderName::name);
57 index->addProperty<QString>(Mail::Subject::name);
58 index->addProperty<QDateTime>(Mail::Date::name);
59 index->addProperty<QByteArray>(Mail::Folder::name);
60 index->addPropertyWithSorting<QByteArray, QDateTime>(Mail::Folder::name, Mail::Date::name);
61 index->addProperty<QByteArray>(Mail::MessageId::name);
62 index->addProperty<QByteArray>(Mail::ParentMessageId::name);
63
64 index->addProperty<Mail::MessageId>();
65 index->addSecondaryProperty<Mail::MessageId, Mail::ThreadId>();
66 index->addSecondaryProperty<Mail::ThreadId, Mail::MessageId>();
67 } 73 }
68 return *index; 74 return *index;
69} 75}
@@ -122,7 +128,7 @@ static QString stripOffPrefixes(const QString &subject)
122} 128}
123 129
124 130
125static void updateThreadingIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 131static void updateThreadingIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
126{ 132{
127 auto messageId = bufferAdaptor.getProperty(Mail::MessageId::name); 133 auto messageId = bufferAdaptor.getProperty(Mail::MessageId::name);
128 auto parentMessageId = bufferAdaptor.getProperty(Mail::ParentMessageId::name); 134 auto parentMessageId = bufferAdaptor.getProperty(Mail::ParentMessageId::name);
@@ -164,16 +170,17 @@ static void updateThreadingIndex(const QByteArray &identifier, const BufferAdapt
164 } 170 }
165} 171}
166 172
167void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 173void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
168{ 174{
169 SinkTrace() << "Indexing " << identifier; 175 SinkTrace() << "Indexing " << identifier;
170 getIndex().add(identifier, bufferAdaptor, transaction); 176 getIndex().add(identifier, bufferAdaptor, transaction);
171 updateThreadingIndex(identifier, bufferAdaptor, transaction); 177 updateThreadingIndex(identifier, bufferAdaptor, transaction);
172} 178}
173 179
174void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 180void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
175{ 181{
176 getIndex().remove(identifier, bufferAdaptor, transaction); 182 getIndex().remove(identifier, bufferAdaptor, transaction);
183 //TODO cleanup threading index
177} 184}
178 185
179QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() 186QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper()
@@ -218,18 +225,21 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty
218} 225}
219 226
220 227
221DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) 228DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::EntityStore::Ptr store)
222{ 229{
223 auto mapper = initializeReadPropertyMapper(); 230 auto mapper = initializeReadPropertyMapper();
224 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper, &transaction](const Sink::Entity &entity, const QByteArray &property) -> QVariant { 231 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), store, getIndex(), [mapper, store](const Sink::Entity &entity, const QByteArray &property) -> QVariant {
225 if (property == Mail::ThreadId::name) { 232 if (property == Mail::ThreadId::name) {
226 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); 233 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local());
227 Q_ASSERT(localBuffer); 234 Q_ASSERT(localBuffer);
228 auto messageId = mapper->getProperty(Mail::MessageId::name, localBuffer); 235 auto messageId = mapper->getProperty(Mail::MessageId::name, localBuffer);
236 //FIXME
229 //This is an index property that we have too lookup 237 //This is an index property that we have too lookup
230 auto thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId, transaction); 238 /* auto thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); */
231 Q_ASSERT(!thread.isEmpty()); 239 /* auto thread = store->secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); */
232 return thread.first(); 240 /* Q_ASSERT(!thread.isEmpty()); */
241 /* return thread.first(); */
242 return QVariant();
233 } else { 243 } else {
234 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); 244 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local());
235 Q_ASSERT(localBuffer); 245 Q_ASSERT(localBuffer);