summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-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);