From 8eb78ae01b2aecb1ca5f2456faccd8f87cfadf73 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 18 Sep 2020 18:20:59 +0300 Subject: [PATCH] sidebar: compute mailbox tree only for subscribed mailboxes --- src/conf/accounts.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 95d642ada..6f329c1cc 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -2157,10 +2157,24 @@ fn build_mailboxes_order( } drop(stack); for node in tree.iter_mut() { - fn rec(node: &mut MailboxNode, depth: usize, mut indentation: u32, has_sibling: bool) { + fn rec( + node: &mut MailboxNode, + mailbox_entries: &IndexMap, + depth: usize, + mut indentation: u32, + has_sibling: bool, + ) { node.indentation = indentation; node.has_sibling = has_sibling; - let mut iter = (0..node.children.len()).peekable(); + let mut iter = (0..node.children.len()) + .filter(|i| { + mailbox_entries[&node.children[*i].hash] + .ref_mailbox + .is_subscribed() + }) + .collect::>() + .into_iter() + .peekable(); if has_sibling { indentation <<= 1; indentation |= 1; @@ -2169,10 +2183,16 @@ fn build_mailboxes_order( } while let Some(i) = iter.next() { let c = &mut node.children[i]; - rec(c, depth + 1, indentation, iter.peek() != None); + rec( + c, + mailbox_entries, + depth + 1, + indentation, + iter.peek() != None, + ); } }; - rec(node, 0, 1, false); + rec(node, &mailbox_entries, 0, 1, false); } }