diff --git a/src/components.rs b/src/components.rs index dca1b6cd..a4ec8dc4 100644 --- a/src/components.rs +++ b/src/components.rs @@ -75,7 +75,7 @@ pub trait Component: Display + Debug + Send { Default::default() } - fn get_status(&self, _context: &Context) -> Option { - None + fn get_status(&self, _context: &Context) -> String { + String::new() } } diff --git a/src/components/contacts/contact_list.rs b/src/components/contacts/contact_list.rs index 66063796..95e66052 100644 --- a/src/components/contacts/contact_list.rs +++ b/src/components/contacts/contact_list.rs @@ -670,7 +670,7 @@ impl Component for ContactList { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } @@ -707,7 +707,7 @@ impl Component for ContactList { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } return true; @@ -894,10 +894,10 @@ impl Component for ContactList { .unwrap_or(true) } - fn get_status(&self, context: &Context) -> Option { - Some(format!( + fn get_status(&self, context: &Context) -> String { + format!( "{} entries", context.accounts[self.account_pos].address_book.len() - )) + ) } } diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 60af1d8f..6806f9eb 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -545,7 +545,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); return true; } @@ -613,7 +613,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); return true; } @@ -798,7 +798,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } UIEvent::MailboxUpdate(_) => { @@ -806,7 +806,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) => { @@ -852,32 +852,27 @@ impl Component for Listing { self.component.set_id(id); } - fn get_status(&self, context: &Context) -> Option { - Some({ - let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0] - .folders_order - .get(self.cursor_pos.1) - { - *h - } else { - return Some(String::new()); - }; - if !context.accounts[self.cursor_pos.0].folders[&folder_hash].is_available() { - return Some(String::new()); - } - let account = &context.accounts[self.cursor_pos.0]; - let m = if account[self.cursor_pos.1].is_available() { - account[self.cursor_pos.1].unwrap() - } else { - return Some(String::new()); - }; + fn get_status(&self, context: &Context) -> String { + let folder_hash = if let Some((_, folder_hash)) = self.accounts[self.cursor_pos.0] + .entries + .get(self.cursor_pos.1) + { + *folder_hash + } else { + return String::new(); + }; + + let account = &context.accounts[self.cursor_pos.0]; + if let Ok(m) = account[folder_hash].as_result() { format!( "Mailbox: {}, Messages: {}, New: {}", m.folder.name(), m.envelopes.len(), m.folder.count().ok().map(|(v, _)| v).unwrap_or(0), ) - }) + } else { + account[folder_hash].to_string() + } } } diff --git a/src/components/utilities.rs b/src/components/utilities.rs index 03c04290..0d9ecd99 100644 --- a/src/components/utilities.rs +++ b/src/components/utilities.rs @@ -1619,9 +1619,7 @@ impl Component for Tabbed { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.children[self.cursor_pos] - .get_status(context) - .unwrap_or_default(), + self.children[self.cursor_pos].get_status(context), ))); self.set_dirty(true); } @@ -1632,9 +1630,7 @@ impl Component for Tabbed { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.children[self.cursor_pos] - .get_status(context) - .unwrap_or_default(), + self.children[self.cursor_pos].get_status(context), ))); self.set_dirty(true); return true;