diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-08-12 16:55:45 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:28 +0300 |
commit | 5889494e9e4d6c51aa87e6433f2dfdbfb8b4846a (patch) | |
tree | ac78d166e6b97d2b2515478d9c4490dc06ce2698 /ui | |
parent | e316640f682fa05d0b12168219a2dd8000fb4ec5 (diff) |
Move backend logic to backend and keep Envelope abstract
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 44 | ||||
-rw-r--r-- | ui/src/components/mail/listing/mod.rs | 56 | ||||
-rw-r--r-- | ui/src/components/mail/view/mod.rs | 19 |
3 files changed, 85 insertions, 34 deletions
diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 71159b3d..46e84d86 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -20,6 +20,7 @@ */ use super::*; +use melib::mailbox::backends::BackendOp; const MAX_COLS: usize = 500; /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the thread's content in a @@ -89,7 +90,7 @@ impl CompactMailListing { break; } } - let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] + let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] .as_ref() .unwrap(); @@ -188,6 +189,7 @@ impl CompactMailListing { container, &indentations, len, + context.accounts[self.cursor_pos.0].backend.operation(envelope.hash()), ), &mut content, fg_color, @@ -347,6 +349,7 @@ impl CompactMailListing { container: &Container, indentations: &[bool], idx_width: usize, + op: Box<BackendOp>, ) -> String { let has_sibling = container.has_sibling(); let has_parent = container.has_parent(); @@ -383,7 +386,7 @@ impl CompactMailListing { if show_subject { s.push_str(&format!("{:.85}", envelope.subject())); } - let attach_count = envelope.body().count_attachments(); + let attach_count = envelope.body(op).count_attachments(); if attach_count > 1 { s.push_str(&format!(" {}∞ ", attach_count - 1)); } @@ -439,17 +442,34 @@ impl Component for CompactMailListing { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings .threaded; - let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_mut() - .unwrap(); - let envelope: &mut Envelope = if threaded { - let i = mailbox.threaded_mail(idx); - &mut mailbox.collection[i] - } else { - &mut mailbox.collection[idx] + let account = &mut context.accounts[self.cursor_pos.0]; + let (hash, is_seen) = { + let mailbox = &mut account[self.cursor_pos.1] + .as_mut() + .unwrap(); + let envelope: &mut Envelope = if threaded { + let i = mailbox.threaded_mail(idx); + &mut mailbox.collection[i] + } else { + &mut mailbox.collection[idx] + }; + (envelope.hash(), envelope.is_seen()) }; - if !envelope.is_seen() { - envelope.set_seen().unwrap(); + if is_seen { + let op = { + let backend = &account.backend; + backend.operation(hash) + }; + let mailbox = &mut account[self.cursor_pos.1] + .as_mut() + .unwrap(); + let envelope: &mut Envelope = if threaded { + let i = mailbox.threaded_mail(idx); + &mut mailbox.collection[i] + } else { + &mut mailbox.collection[idx] + }; + envelope.set_seen(op).unwrap(); true } else { false diff --git a/ui/src/components/mail/listing/mod.rs b/ui/src/components/mail/listing/mod.rs index 55aebc54..21863ac6 100644 --- a/ui/src/components/mail/listing/mod.rs +++ b/ui/src/components/mail/listing/mod.rs @@ -21,6 +21,7 @@ use super::*; +use melib::mailbox::backends::BackendOp; mod compact; pub use self::compact::*; @@ -107,7 +108,7 @@ impl MailListing { break; } } - let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] + let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] .as_ref() .unwrap(); @@ -139,10 +140,18 @@ impl MailListing { let threads: &Vec<Container> = &mailbox.threads; local_collection.sort_by(|a, b| match self.sort { (SortField::Date, SortOrder::Desc) => { - mailbox.thread(*b).date().cmp(&mailbox.thread(*a).date()) + let a = mailbox.thread(*a); + let b = mailbox.thread(*b); + let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; + let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; + mb.date().cmp(&ma.date()) } (SortField::Date, SortOrder::Asc) => { - mailbox.thread(*a).date().cmp(&mailbox.thread(*b).date()) + let a = mailbox.thread(*a); + let b = mailbox.thread(*b); + let ma = &mailbox.collection[*a.message().as_ref().unwrap()]; + let mb = &mailbox.collection[*b.message().as_ref().unwrap()]; + ma.date().cmp(&mb.date()) } (SortField::Subject, SortOrder::Desc) => { let a = mailbox.thread(*a); @@ -211,6 +220,7 @@ impl MailListing { container, &indentations, len, + context.accounts[self.cursor_pos.0].backend.operation(envelope.hash()) ), &mut content, fg_color, @@ -411,6 +421,7 @@ impl MailListing { container: &Container, indentations: &[bool], idx_width: usize, + op: Box<BackendOp>, ) -> String { let has_sibling = container.has_sibling(); let has_parent = container.has_parent(); @@ -447,7 +458,7 @@ impl MailListing { if show_subject { s.push_str(&format!("{:.85}", envelope.subject())); } - let attach_count = envelope.body().count_attachments(); + let attach_count = envelope.body(op).count_attachments(); if attach_count > 1 { s.push_str(&format!(" {}∞ ", attach_count - 1)); } @@ -503,17 +514,34 @@ impl Component for MailListing { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings .threaded; - let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] - .as_mut() - .unwrap(); - let envelope: &mut Envelope = if threaded { - let i = mailbox.threaded_mail(idx); - &mut mailbox.collection[i] - } else { - &mut mailbox.collection[idx] + let account = &mut context.accounts[self.cursor_pos.0]; + let (hash, is_seen) = { + let mailbox = &mut account[self.cursor_pos.1] + .as_mut() + .unwrap(); + let envelope: &mut Envelope = if threaded { + let i = mailbox.threaded_mail(idx); + &mut mailbox.collection[i] + } else { + &mut mailbox.collection[idx] + }; + (envelope.hash(), envelope.is_seen()) }; - if !envelope.is_seen() { - envelope.set_seen().unwrap(); + if !is_seen { + let op = { + let backend = &account.backend; + backend.operation(hash) + }; + let mailbox = &mut account[self.cursor_pos.1] + .as_mut() + .unwrap(); + let envelope: &mut Envelope = if threaded { + let i = mailbox.threaded_mail(idx); + &mut mailbox.collection[i] + } else { + &mut mailbox.collection[idx] + }; + envelope.set_seen(op).unwrap(); true } else { false diff --git a/ui/src/components/mail/view/mod.rs b/ui/src/components/mail/view/mod.rs index 25c7733e..724e0657 100644 --- a/ui/src/components/mail/view/mod.rs +++ b/ui/src/components/mail/view/mod.rs @@ -303,11 +303,12 @@ impl Component for MailView { if self.dirty { let mailbox_idx = self.coordinates; // coordinates are mailbox idxs - let mailbox = &mut context.accounts[mailbox_idx.0][mailbox_idx.1] + let mailbox = &context.accounts[mailbox_idx.0][mailbox_idx.1] .as_ref() .unwrap(); let envelope: &Envelope = &mailbox.collection[envelope_idx]; - let body = envelope.body(); + let op = context.accounts[mailbox_idx.0].backend.operation(envelope.hash()); + let body = envelope.body(op); match self.mode { ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => { self.subview = Some(Box::new(HtmlView::new(decode( @@ -372,9 +373,9 @@ impl Component for MailView { self.cmd_buf.clear(); { - let accounts = &mut context.accounts; + let accounts = &context.accounts; let threaded = accounts[self.coordinates.0].runtime_settings.threaded; - let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1] + let mailbox = &accounts[self.coordinates.0][self.coordinates.1] .as_ref() .unwrap(); let envelope_idx: usize = if threaded { @@ -384,7 +385,8 @@ impl Component for MailView { }; let envelope: &Envelope = &mailbox.collection[envelope_idx]; - if let Some(u) = envelope.body().attachments().get(lidx) { + let op = context.accounts[self.coordinates.0].backend.operation(envelope.hash()); + if let Some(u) = envelope.body(op).attachments().get(lidx) { match u.content_type().0 { ContentType::Text { .. } => { self.mode = ViewMode::Attachment(lidx); @@ -443,9 +445,9 @@ impl Component for MailView { let lidx = self.cmd_buf.parse::<usize>().unwrap(); self.cmd_buf.clear(); let url = { - let accounts = &mut context.accounts; + let accounts = &context.accounts; let threaded = accounts[self.coordinates.0].runtime_settings.threaded; - let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1] + let mailbox = &accounts[self.coordinates.0][self.coordinates.1] .as_ref() .unwrap(); let envelope_idx: usize = if threaded { @@ -456,7 +458,8 @@ impl Component for MailView { let envelope: &Envelope = &mailbox.collection[envelope_idx]; let finder = LinkFinder::new(); - let mut t = envelope.body().text().to_string(); + let op = context.accounts[self.coordinates.0].backend.operation(envelope.hash()); + let mut t = envelope.body(op).text().to_string(); let links: Vec<Link> = finder.links(&t).collect(); if let Some(u) = links.get(lidx) { u.as_str().to_string() |