From 4a33cd02bef5fba633d99cf0e8f5ca55a25e8384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 28 Apr 2021 23:49:03 +0200 Subject: try look for sent messages --- src/state/threads.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/state/threads.rs') 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, i: usize, - query: Option, + query: String, } pub struct Thread { @@ -42,29 +42,29 @@ impl<'d, 'q> Thread { } } -impl<'d, 'q> Threads { - pub fn from_query(query: Option, 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(&mut self, out: &mut W) { + pub fn init(&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(), _ => (), } -- cgit v1.2.1