aboutsummaryrefslogtreecommitdiffstats
path: root/src/state/threads.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/threads.rs')
-rw-r--r--src/state/threads.rs48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/state/threads.rs b/src/state/threads.rs
index 4248d93..9d81e09 100644
--- a/src/state/threads.rs
+++ b/src/state/threads.rs
@@ -6,8 +6,10 @@ use std::io::Write;
use termion::{color, event::Key};
pub struct Threads {
- pub threads: Vec<Thread>,
- pub i: isize,
+ threads: Vec<Thread>,
+ i: isize,
+
+ query: Option<String>,
}
pub struct Thread {
@@ -17,7 +19,16 @@ pub struct Thread {
messages: Vec<String>,
}
-impl Thread {
+impl<'d, 'q> Thread {
+ pub fn new(thread: notmuch::Thread<'d, 'q>) -> Self {
+ Self {
+ subject: thread.subject().to_string(),
+ authors: thread.authors().clone(),
+ _id: thread.id().to_string(),
+ messages: thread.messages().map(|m| m.id().to_string()).collect(),
+ }
+ }
+
pub fn remove_tag(&self, tag: &str) {
let db = db::open(DatabaseMode::ReadWrite).unwrap();
for m_id in self.messages.iter() {
@@ -32,17 +43,27 @@ impl Thread {
}
impl<'d, 'q> Threads {
- pub fn new(threads: notmuch::Threads<'d, 'q>) -> Self {
- let threads = threads.map(|t| Thread {
- subject: t.subject().to_string(),
- authors: t.authors().clone(),
- _id: t.id().to_string(),
- messages: t.messages().map(|m| m.id().to_string()).collect(),
- }).collect();
-
+ pub fn from_query(query: Option<String>, threads: notmuch::Threads<'d, 'q>) -> Self {
Self {
- threads,
- i: 0
+ threads: threads.map(Thread::new).collect(),
+ i: 0,
+ query,
+ }
+ }
+
+ 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();
+ if self.i >= self.threads.len() as isize {
+ self.i = self.threads.len() as isize - 1;
+ }
}
}
@@ -57,6 +78,7 @@ impl<'d, 'q> Threads {
Key::Char('i') => {
self.threads[self.i as usize].remove_tag("inbox");
}
+ Key::Char('r') => self.reload(),
_ => (),
}
self.i = self.i.rem_euclid(self.threads.len() as isize);