diff options
Diffstat (limited to 'src/state/threads.rs')
| -rw-r--r-- | src/state/threads.rs | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/state/threads.rs b/src/state/threads.rs index b6fddbb..be566e5 100644 --- a/src/state/threads.rs +++ b/src/state/threads.rs @@ -9,7 +9,7 @@ pub struct Threads { threads: Vec<Thread>, i: usize, - query: Option<String>, + query: String, } pub struct Thread { @@ -42,29 +42,29 @@ impl<'d, 'q> Thread { } } -impl<'d, 'q> Threads { - pub fn from_query(query: Option<String>, threads: notmuch::Threads<'d, 'q>) -> Self { - Self { - threads: threads.map(Thread::new).collect(), +impl Threads { + pub fn from_query(query: String) -> Self { + let mut res = Self { + threads: Vec::new(), i: 0, query, - } + }; + res.reload(); + res } pub fn reload(&mut self) { - if let Some(query) = &self.query { - self.threads = db::open(DatabaseMode::ReadOnly) - .unwrap() - .create_query(query) - .unwrap() - .search_threads() - .unwrap() - .map(Thread::new) - .collect(); - } + self.threads = db::open(DatabaseMode::ReadOnly) + .unwrap() + .create_query(&self.query) + .unwrap() + .search_threads() + .unwrap() + .map(Thread::new) + .collect(); } - pub fn init<W: Write>(&mut self, out: &mut W) { + pub fn init<W: Write>(&self, out: &mut W) { draw(&self, out); } @@ -80,6 +80,11 @@ impl<'d, 'q> Threads { Key::Char('i') => { self.threads[self.i].remove_tag("inbox"); } + Key::Char('s') => { + let sent = Threads::from_query(String::from("tag:sent")); + sent.init(out); + return Some(State::Threads(sent)); + } Key::Char('r') => self.reload(), _ => (), } |
