diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-05-14 21:47:47 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:49 +0300 |
commit | 22d868f499bbf617a530fd67754c46a15896c4ec (patch) | |
tree | af124c4d4948f4de39a2f9114065cd53fcc6c985 /ui | |
parent | 4582bcd5ae6a5ad7725a5a89f3e421de007d1525 (diff) |
save Account to disk
closes #114
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail.rs | 1 | ||||
-rw-r--r-- | ui/src/components/mail/compose.rs | 12 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 24 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 12 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 51 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 13 | ||||
-rw-r--r-- | ui/src/conf/mailer.rs | 2 | ||||
-rw-r--r-- | ui/src/conf/pager.rs | 2 | ||||
-rw-r--r-- | ui/src/execute/actions.rs | 5 |
9 files changed, 70 insertions, 52 deletions
diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs index 29281e85..e706982c 100644 --- a/ui/src/components/mail.rs +++ b/ui/src/components/mail.rs @@ -24,6 +24,7 @@ use super::*; use melib::backends::Folder; use melib::backends::FolderHash; +use melib::thread::ThreadHash; pub mod listing; pub use listing::*; diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 9e6bb3d1..554fc896 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -127,14 +127,14 @@ impl Composer { * msg: index of message we reply to in thread_nodes * context: current context */ - pub fn edit(coordinates: (usize, usize, usize), msg: usize, context: &Context) -> Self { + pub fn edit(coordinates: (usize, usize, usize), msg: ThreadHash, context: &Context) -> Self { let mailbox = &context.accounts[coordinates.0][coordinates.1] .as_ref() .unwrap(); let threads = &mailbox.collection.threads; let thread_nodes = &threads.thread_nodes(); let mut ret = Composer::default(); - let message = &mailbox.collection[&thread_nodes[msg].message().unwrap()]; + let message = &mailbox.collection[&thread_nodes[&msg].message().unwrap()]; let op = context.accounts[coordinates.0] .backend .operation(message.hash(), mailbox.folder.hash()); @@ -144,14 +144,18 @@ impl Composer { ret.account_cursor = coordinates.0; ret } - pub fn with_context(coordinates: (usize, usize, usize), msg: usize, context: &Context) -> Self { + pub fn with_context( + coordinates: (usize, usize, usize), + msg: ThreadHash, + context: &Context, + ) -> Self { let mailbox = &context.accounts[coordinates.0][coordinates.1] .as_ref() .unwrap(); let threads = &mailbox.collection.threads; let thread_nodes = &threads.thread_nodes(); let mut ret = Composer::default(); - let p = &thread_nodes[msg]; + let p = &thread_nodes[&msg]; let parent_message = &mailbox.collection[&p.message().unwrap()]; let mut op = context.accounts[coordinates.0] .backend diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 53d7ceff..39978e03 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -207,15 +207,15 @@ impl MailboxView { threads.sort_by(self.sort, self.subsort, &mailbox.collection); for (idx, root_idx) in threads.root_iter().enumerate() { - let thread_node = &threads.thread_nodes()[root_idx]; + let thread_node = &threads.thread_nodes()[&root_idx]; let i = if let Some(i) = thread_node.message() { i } else { let mut iter_ptr = thread_node.children()[0]; - while threads.thread_nodes()[iter_ptr].message().is_none() { - iter_ptr = threads.thread_nodes()[iter_ptr].children()[0]; + while threads.thread_nodes()[&iter_ptr].message().is_none() { + iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0]; } - threads.thread_nodes()[iter_ptr].message().unwrap() + threads.thread_nodes()[&iter_ptr].message().unwrap() }; if !mailbox.collection.contains_key(&i) { debug!("key = {}", i); @@ -251,15 +251,15 @@ impl MailboxView { }; for ((idx, root_idx), strings) in threads.root_iter().enumerate().zip(rows) { - let thread_node = &threads.thread_nodes()[root_idx]; + let thread_node = &threads.thread_nodes()[&root_idx]; let i = if let Some(i) = thread_node.message() { i } else { let mut iter_ptr = thread_node.children()[0]; - while threads.thread_nodes()[iter_ptr].message().is_none() { - iter_ptr = threads.thread_nodes()[iter_ptr].children()[0]; + while threads.thread_nodes()[&iter_ptr].message().is_none() { + iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0]; } - threads.thread_nodes()[iter_ptr].message().unwrap() + threads.thread_nodes()[&iter_ptr].message().unwrap() }; if !mailbox.collection.contains_key(&i) { debug!("key = {}", i); @@ -354,15 +354,15 @@ impl MailboxView { } let threads = &mailbox.collection.threads; let thread_node = threads.root_set(idx); - let thread_node = &threads.thread_nodes()[thread_node]; + let thread_node = &threads.thread_nodes()[&thread_node]; let i = if let Some(i) = thread_node.message() { i } else { let mut iter_ptr = thread_node.children()[0]; - while threads.thread_nodes()[iter_ptr].message().is_none() { - iter_ptr = threads.thread_nodes()[iter_ptr].children()[0]; + while threads.thread_nodes()[&iter_ptr].message().is_none() { + iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0]; } - threads.thread_nodes()[iter_ptr].message().unwrap() + threads.thread_nodes()[&iter_ptr].message().unwrap() }; let root_envelope: &Envelope = &mailbox.collection[&i]; diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index 6bc19484..0501751f 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -151,12 +151,12 @@ impl ThreadListing { /* Draw threaded view. */ let threads = &mailbox.collection.threads; threads.sort_by(self.sort, self.subsort, &mailbox.collection); - let thread_nodes: &Vec<ThreadNode> = &threads.thread_nodes(); + let thread_nodes: &FnvHashMap<ThreadHash, ThreadNode> = &threads.thread_nodes(); let mut iter = threads.threads_iter().peekable(); /* This is just a desugared for loop so that we can use .peek() */ let mut idx = 0; - while let Some((indentation, i, has_sibling)) = iter.next() { - let thread_node = &thread_nodes[i]; + while let Some((indentation, thread_hash, has_sibling)) = iter.next() { + let thread_node = &thread_nodes[&thread_hash]; if indentation == 0 { thread_idx += 1; @@ -181,7 +181,7 @@ impl ThreadListing { envelope, idx, indentation, - i, + thread_hash, threads, &indentations, has_sibling, @@ -362,13 +362,13 @@ impl ThreadListing { envelope: &Envelope, idx: usize, indent: usize, - node_idx: usize, + node_idx: ThreadHash, threads: &Threads, indentations: &[bool], has_sibling: bool, //op: Box<BackendOp>, ) -> String { - let thread_node = &threads[node_idx]; + let thread_node = &threads[&node_idx]; let has_parent = thread_node.has_parent(); let show_subject = thread_node.show_subject(); diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 31ab4abd..3f0099c0 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -24,7 +24,7 @@ use std::cmp; #[derive(Debug, Clone)] struct ThreadEntry { - index: (usize, usize, usize), + index: (usize, ThreadHash, usize), /// (indentation, thread_node index, line number in listing) indentation: usize, msg_hash: EnvelopeHash, @@ -57,13 +57,13 @@ impl ThreadView { const DESCRIPTION: &'static str = "thread view"; /* * coordinates: (account index, mailbox index, root set thread_node index) - * expanded_idx: optional position of expanded entry when we render the threadview. Default + * expanded_hash: optional position of expanded entry when we render the threadview. Default * expanded message is the last one. * context: current context */ pub fn new( coordinates: (usize, usize, usize), - expanded_idx: Option<usize>, + expanded_hash: Option<ThreadHash>, context: &Context, ) -> Self { let mut view = ThreadView { @@ -79,7 +79,7 @@ impl ThreadView { id: ComponentId::new_v4(), ..Default::default() }; - view.initiate(expanded_idx, context); + view.initiate(expanded_hash, context); view.new_cursor_pos = view.new_expanded_pos; view } @@ -102,8 +102,8 @@ impl ThreadView { None }; - let expanded_pos = self.expanded_pos; - self.initiate(Some(expanded_pos), context); + let expanded_hash = old_expanded_entry.as_ref().map(|e| e.index.1); + self.initiate(expanded_hash, context); let mut old_cursor = 0; let mut new_cursor = 0; @@ -144,7 +144,7 @@ impl ThreadView { } self.set_dirty(); } - fn initiate(&mut self, expanded_idx: Option<usize>, context: &Context) { + fn initiate(&mut self, expanded_hash: Option<ThreadHash>, context: &Context) { /* stack to push thread messages in order in order to pop and print them later */ let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1] .as_ref() @@ -153,23 +153,23 @@ impl ThreadView { let thread_iter = threads.thread_iter(self.coordinates.2); self.entries.clear(); - for (line, (ind, idx)) in thread_iter.enumerate() { - let entry = if let Some(msg_hash) = threads.thread_nodes()[idx].message() { + for (line, (ind, thread_hash)) in thread_iter.enumerate() { + let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_hash].message() { let seen: bool = mailbox.collection[&msg_hash].is_seen(); - self.make_entry((ind, idx, line), msg_hash, seen) + self.make_entry((ind, thread_hash, line), msg_hash, seen) } else { continue; }; self.entries.push(entry); - match expanded_idx { - Some(expanded_idx) if expanded_idx == idx => { + match expanded_hash { + Some(expanded_hash) if expanded_hash == thread_hash => { self.new_expanded_pos = self.entries.len().saturating_sub(1); self.expanded_pos = self.new_expanded_pos + 1; } _ => {} } } - if expanded_idx.is_none() { + if expanded_hash.is_none() { self.new_expanded_pos = self.entries.len().saturating_sub(1); self.expanded_pos = self.new_expanded_pos + 1; } @@ -181,7 +181,7 @@ impl ThreadView { Vec::with_capacity(self.entries.len()); for e in &mut self.entries { let envelope: &Envelope = &mailbox.collection[&e.msg_hash]; - let thread_node = &threads.thread_nodes()[e.index.1]; + let thread_node = &threads.thread_nodes()[&e.index.1]; let string = if thread_node.show_subject() { let subject = envelope.subject(); highlight_reply_subjects.push(Some(subject.grapheme_width())); @@ -324,7 +324,7 @@ impl ThreadView { fn make_entry( &mut self, - i: (usize, usize, usize), + i: (usize, ThreadHash, usize), msg_hash: EnvelopeHash, seen: bool, ) -> ThreadEntry { @@ -535,11 +535,11 @@ impl ThreadView { .as_ref() .unwrap(); let threads = &mailbox.collection.threads; - let thread_node = &threads.thread_nodes()[threads.root_set(self.coordinates.2)]; + let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { i } else { - threads.thread_nodes()[thread_node.children()[0]] + threads.thread_nodes()[&thread_node.children()[0]] .message() .unwrap() }; @@ -615,15 +615,15 @@ impl ThreadView { .as_ref() .unwrap(); let threads = &mailbox.collection.threads; - let thread_node = &threads.thread_nodes()[threads.root_set(self.coordinates.2)]; + let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { i } else { let mut iter_ptr = thread_node.children()[0]; - while threads.thread_nodes()[iter_ptr].message().is_none() { - iter_ptr = threads.thread_nodes()[iter_ptr].children()[0]; + while threads.thread_nodes()[&iter_ptr].message().is_none() { + iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0]; } - threads.thread_nodes()[iter_ptr].message().unwrap() + threads.thread_nodes()[&iter_ptr].message().unwrap() }; let envelope: &Envelope = &mailbox.collection[&i]; @@ -835,11 +835,12 @@ impl Component for ThreadView { .as_ref() .unwrap(); let threads = &mailbox.collection.threads; - let thread_node = &threads.thread_nodes()[threads.root_set(self.coordinates.2)]; + let thread_node = + &threads.thread_nodes()[&threads.root_set(self.coordinates.2)]; let i = if let Some(i) = thread_node.message() { i } else { - threads.thread_nodes()[thread_node.children()[0]] + threads.thread_nodes()[&thread_node.children()[0]] .message() .unwrap() }; @@ -890,8 +891,8 @@ impl Component for ThreadView { } UIEvent::Input(Key::Ctrl('r')) => { self.reversed = !self.reversed; - let expanded_pos = self.expanded_pos; - self.initiate(Some(expanded_pos), context); + let expanded_hash = self.entries[self.expanded_pos].index.1; + self.initiate(Some(expanded_hash), context); self.initiated = false; self.dirty = true; return true; diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 1a755f6f..a927193d 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -92,6 +92,17 @@ impl Drop for Account { let writer = io::BufWriter::new(f); serde_json::to_writer(writer, &self.address_book).unwrap(); }; + if let Ok(data) = data_dir.place_data_file("mailbox") { + /* place result in cache directory */ + let f = match fs::File::create(data) { + Ok(f) => f, + Err(e) => { + panic!("{}", e); + } + }; + let writer = io::BufWriter::new(f); + bincode::serialize_into(writer, &self.folders).unwrap(); + }; } } @@ -125,7 +136,7 @@ impl<'a> Iterator for MailboxIterator<'a> { } } -#[derive(Debug, Default)] +#[derive(Serialize, Debug, Default)] struct FolderNode { hash: FolderHash, kids: Vec<FolderNode>, diff --git a/ui/src/conf/mailer.rs b/ui/src/conf/mailer.rs index e555746f..56fc6641 100644 --- a/ui/src/conf/mailer.rs +++ b/ui/src/conf/mailer.rs @@ -20,7 +20,7 @@ */ /// Settings for the mailer function. -#[derive(Debug, Deserialize, Clone, Default)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MailerSettings { /// A command to pipe new emails to /// Required diff --git a/ui/src/conf/pager.rs b/ui/src/conf/pager.rs index 59eaa2fc..1aa822f5 100644 --- a/ui/src/conf/pager.rs +++ b/ui/src/conf/pager.rs @@ -21,7 +21,7 @@ use super::default_vals::*; /// Settings for the pager function. -#[derive(Debug, Deserialize, Clone, Default)] +#[derive(Debug, Deserialize, Clone, Default, Serialize)] pub struct PagerSettings { /// Number of context lines when going to next page. /// Default: 0 diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index a84232b8..5402c846 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -25,6 +25,7 @@ use components::Component; pub use melib::mailbox::{SortField, SortOrder}; +use melib::thread::ThreadHash; extern crate uuid; use uuid::Uuid; @@ -40,9 +41,9 @@ pub enum ListingAction { pub enum TabAction { TabOpen(Option<Box<Component>>), NewDraft(usize), - Reply((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx + Reply((usize, usize, usize), ThreadHash), // thread coordinates (account, mailbox, root_set idx) and thread hash Close, - Edit((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx + Edit((usize, usize, usize), ThreadHash), // thread coordinates (account, mailbox, root_set idx) and thread hash Kill(Uuid), } |