From baa44109f25577756428262bba35c71f830ecc91 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 20 Sep 2020 13:37:59 +0300 Subject: [PATCH] melib/thread: "merge" duplicate messages in threads --- melib/src/thread.rs | 19 +++++++++++++------ src/conf/accounts.rs | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/melib/src/thread.rs b/melib/src/thread.rs index 0b765a03b..0fef1cb7b 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -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 = 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, diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 4df1086d1..593f14b80 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -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)); }