summaryrefslogtreecommitdiffstats
path: root/common/mail/threadindexer.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 12:42:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 12:42:31 +0200
commitc12a9a09da59b9e418316dba02e6215cb55e47ee (patch)
tree05498d9a42e399bcca787f40c1fc473fb09e680e /common/mail/threadindexer.cpp
parent55fe06979ceebe67553135b43aa47e70d931304b (diff)
parentebdb89b8bb482bbb5ecd544c3d38bef35fc7d820 (diff)
downloadsink-c12a9a09da59b9e418316dba02e6215cb55e47ee.tar.gz
sink-c12a9a09da59b9e418316dba02e6215cb55e47ee.zip
Merge commit 'ebdb89b8bb482bbb5ecd544c3d38bef35fc7d820'v0.4.0
Diffstat (limited to 'common/mail/threadindexer.cpp')
-rw-r--r--common/mail/threadindexer.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index 4171d85..1401fc8 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -34,9 +34,37 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
34 34
35 QVector<QByteArray> thread; 35 QVector<QByteArray> thread;
36 36
37 //a child already registered our thread. 37 //check if a child already registered our thread.
38 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); 38 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId);
39 39
40 if (!thread.isEmpty()) {
41 //A child already registered our thread so we merge the childs thread
42 //* check if we have a parent thread, if not just continue as usual
43 //* get all messages that have the same threadid as the child
44 //* switch all to the parents thread
45 auto parentThread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId);
46 if (!parentThread.isEmpty()) {
47 auto childThreadId = thread.first();
48 auto parentThreadId = parentThread.first();
49 SinkTrace() << "Merging child thread: " << childThreadId << " into parent thread: " << parentThreadId;
50
51 //Ensure this mail ends up in the correct thread
52 index().unindex<Mail::MessageId, Mail::ThreadId>(messageId, childThreadId, transaction);
53 //We have to copy the id here, otherwise it doesn't survive the subsequent writes
54 thread = QVector<QByteArray>() << QByteArray{parentThreadId.data(), parentThreadId.size()};
55
56 //Merge all child messages into the correct thread
57 auto childThreadMessageIds = index().secondaryLookup<Mail::ThreadId, Mail::MessageId>(childThreadId);
58 for (const auto &msgId : childThreadMessageIds) {
59 SinkTrace() << "Merging child message: " << msgId;
60 index().unindex<Mail::MessageId, Mail::ThreadId>(msgId, childThreadId, transaction);
61 index().unindex<Mail::ThreadId, Mail::MessageId>(childThreadId, msgId, transaction);
62 index().index<Mail::MessageId, Mail::ThreadId>(msgId, parentThreadId, transaction);
63 index().index<Mail::ThreadId, Mail::MessageId>(parentThreadId, msgId, transaction);
64 }
65 }
66 }
67
40 //If parent is already available, add to thread of parent 68 //If parent is already available, add to thread of parent
41 if (thread.isEmpty() && parentMessageId.isValid()) { 69 if (thread.isEmpty() && parentMessageId.isValid()) {
42 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); 70 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId);