melib/thread: "merge" duplicate messages in threads

This commit is contained in:
Manos Pitsidianakis 2020-09-20 13:37:59 +03:00
parent 28deba708c
commit baa44109f2
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710
2 changed files with 40 additions and 21 deletions

View File

@ -33,6 +33,7 @@
*/
use crate::datetime::UnixTimestamp;
use crate::email::address::StrBuild;
use crate::email::parser::BytesExt;
use crate::email::*;
@ -655,12 +656,21 @@ impl Threads {
let envelopes_lck = envelopes.read().unwrap();
let reply_to_id: Option<ThreadNodeHash> = envelopes_lck[&env_hash]
.in_reply_to()
.map(crate::email::StrBuild::raw)
.map(StrBuild::raw)
.and_then(|r| self.message_ids.get(r).cloned());
let message_id = envelopes_lck[&env_hash].message_id().raw();
if self.message_ids_set.contains(message_id)
if self.message_ids.contains_key(message_id)
&& !self.missing_message_ids.contains(message_id)
{
let thread_hash = self.message_ids[message_id];
drop(envelopes_lck);
envelopes
.write()
.unwrap()
.get_mut(&env_hash)
.unwrap()
.set_thread(thread_hash);
return false;
}
@ -739,10 +749,7 @@ impl Threads {
self.hash_set.insert(env_hash);
if let Some(reply_to_id) = reply_to_id {
make!((reply_to_id) parent of (new_id), self);
} else if let Some(r) = envelopes_lck[&env_hash]
.in_reply_to()
.map(crate::email::StrBuild::raw)
{
} else if let Some(r) = envelopes_lck[&env_hash].in_reply_to().map(StrBuild::raw) {
let reply_to_id = ThreadNodeHash::new();
self.thread_nodes.insert(
reply_to_id,

View File

@ -880,19 +880,24 @@ impl Account {
return Some(UIEvent::MailboxUpdate((self.hash, mailbox_hash)));
}
let thread = {
let thread_hash = self.collection.get_env(env_hash).thread();
self.collection.get_threads(mailbox_hash).find_group(
self.collection.get_threads(mailbox_hash)[&thread_hash].group,
)
};
let thread_hash = self.collection.get_env(env_hash).thread();
if self
.collection
.get_threads(mailbox_hash)
.thread_ref(thread)
.snoozed()
.thread_nodes()
.contains_key(&thread_hash)
{
return Some(UIEvent::MailboxUpdate((self.hash, mailbox_hash)));
let thread = self.collection.get_threads(mailbox_hash).find_group(
self.collection.get_threads(mailbox_hash)[&thread_hash].group,
);
if self
.collection
.get_threads(mailbox_hash)
.thread_ref(thread)
.snoozed()
{
return Some(UIEvent::MailboxUpdate((self.hash, mailbox_hash)));
}
}
if is_seen || is_draft {
return Some(UIEvent::MailboxUpdate((self.hash, mailbox_hash)));
@ -913,12 +918,6 @@ impl Account {
if !self.collection.contains_key(&env_hash) {
return None;
}
let thread_hash = {
let thread_hash = self.collection.get_env(env_hash).thread();
self.collection.get_threads(mailbox_hash).find_group(
self.collection.get_threads(mailbox_hash)[&thread_hash].group,
)
};
#[cfg(feature = "sqlite3")]
if self.settings.conf.search_backend == crate::conf::SearchBackend::Sqlite3 {
if let Err(err) = crate::sqlite3::remove(env_hash) {
@ -935,6 +934,19 @@ impl Account {
);
}
}
let thread_hash = self.collection.get_env(env_hash).thread();
if !self
.collection
.get_threads(mailbox_hash)
.thread_nodes()
.contains_key(&thread_hash)
{
return None;
}
let thread_hash = self
.collection
.get_threads(mailbox_hash)
.find_group(self.collection.get_threads(mailbox_hash)[&thread_hash].group);
self.collection.remove(env_hash, mailbox_hash);
return Some(EnvelopeRemove(env_hash, thread_hash));
}