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.
jmap
Manos Pitsidianakis 2019-11-16 20:24:05 +02:00
parent 1168804cf8
commit f8a1a6caa5
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 19 additions and 10 deletions

View File

@ -612,6 +612,17 @@ impl<'a> Iterator for RootIterator<'a> {
}
}
pub fn find_root_hash(buf: &FnvHashMap<ThreadHash, ThreadNode>, 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<ThreadHash, ThreadNode>, h: ThreadHash) -> ThreadHash {
if buf[&h].thread_group == h {
return h;
@ -654,7 +665,7 @@ fn union(buf: &mut FnvHashMap<ThreadHash, ThreadNode>, 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 {

View File

@ -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

View File

@ -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