diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-08-18 19:04:54 -0600 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-08-18 19:09:32 -0600 |
commit | 3a7d2e81c7fdc8c2e4b9810065028f4906fc28b3 (patch) | |
tree | 4792b784959e9118798d262861467b0d7c7203ff /common/mail | |
parent | d87c789f311b7727d2db687e3891319e98ad6535 (diff) | |
download | sink-3a7d2e81c7fdc8c2e4b9810065028f4906fc28b3.tar.gz sink-3a7d2e81c7fdc8c2e4b9810065028f4906fc28b3.zip |
Implemented thread merging
It can happen that thread messages are not delivered in order, which
means we will have to merge threads once all messages are available.
Diffstat (limited to 'common/mail')
-rw-r--r-- | common/mail/threadindexer.cpp | 30 |
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); |