From f8a1a6caa5345d817c66c1e6fa1ad6d624a4ac77 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 16 Nov 2019 20:24:05 +0200 Subject: [PATCH] melib: replace find_thread_group with find_root_hash thread_group property of ThreadNode doesn't yet reflect the actual root ThreadNode (the root of the thread, that is). So find the root manually instead. --- melib/src/thread.rs | 13 ++++++++++++- ui/src/components/mail/listing/compact.rs | 6 +++--- ui/src/components/mail/listing/conversations.rs | 10 ++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/melib/src/thread.rs b/melib/src/thread.rs index cd25136a..7de5097e 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -612,6 +612,17 @@ impl<'a> Iterator for RootIterator<'a> { } } +pub fn find_root_hash(buf: &FnvHashMap, h: ThreadHash) -> ThreadHash { + if buf[&h].parent.is_none() { + return h; + } + let p = buf[&h].parent.unwrap(); + if buf[&p].message.is_none() { + return h; + } + find_root_hash(buf, p) +} + pub fn find_thread_group(buf: &FnvHashMap, h: ThreadHash) -> ThreadHash { if buf[&h].thread_group == h { return h; @@ -654,7 +665,7 @@ fn union(buf: &mut FnvHashMap, x: ThreadHash, y: ThreadH impl Threads { pub fn is_snoozed(&self, h: ThreadHash) -> bool { - let root = find_thread_group(&self.thread_nodes, h); + let root = find_root_hash(&self.thread_nodes, h); self.thread_nodes[&root].snoozed() } pub fn find(&mut self, i: ThreadHash) -> ThreadHash { diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 5ae67d67..dc25ec00 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -395,7 +395,7 @@ impl ListingTrait for CompactListing { if !threads.thread_nodes.contains_key(&env_hash_thread_hash) { continue; } - let thread_group = melib::find_thread_group( + let thread_group = melib::find_root_hash( &threads.thread_nodes, threads.thread_nodes[&env_hash_thread_hash].thread_group(), ); @@ -1175,7 +1175,7 @@ impl Component for CompactListing { if !threads.thread_nodes.contains_key(&new_env_thread_hash) { return false; } - let thread_group = melib::find_thread_group( + let thread_group = melib::find_root_hash( &threads.thread_nodes, threads.thread_nodes[&new_env_thread_hash].thread_group(), ); @@ -1183,7 +1183,7 @@ impl Component for CompactListing { .order .iter() .find(|(n, _)| { - melib::find_thread_group( + melib::find_root_hash( &threads.thread_nodes, threads.thread_nodes[&n].thread_group(), ) == thread_group diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs index d10df9aa..233cc0f2 100644 --- a/ui/src/components/mail/listing/conversations.rs +++ b/ui/src/components/mail/listing/conversations.rs @@ -372,10 +372,8 @@ impl ListingTrait for ConversationsListing { if !threads.thread_nodes.contains_key(&env_hash_thread_hash) { continue; } - let thread_group = melib::find_thread_group( - &threads.thread_nodes, - threads.thread_nodes[&env_hash_thread_hash].thread_group(), - ); + let thread_group = + melib::find_root_hash(&threads.thread_nodes, env_hash_thread_hash); if self.filtered_order.contains_key(&thread_group) { continue; } @@ -1066,7 +1064,7 @@ impl Component for ConversationsListing { if !threads.thread_nodes.contains_key(&new_env_thread_hash) { return false; } - let thread_group = melib::find_thread_group( + let thread_group = melib::find_root_hash( &threads.thread_nodes, threads.thread_nodes[&new_env_thread_hash].thread_group(), ); @@ -1074,7 +1072,7 @@ impl Component for ConversationsListing { .order .iter() .find(|(n, _)| { - melib::find_thread_group( + melib::find_root_hash( &threads.thread_nodes, threads.thread_nodes[&n].thread_group(), ) == thread_group