view/thread: open the latest email in the thread by default

pull/144/head
Manos Pitsidianakis 2021-09-18 11:36:17 +03:00
parent f975e1004c
commit 20feb50475
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 35 additions and 21 deletions

View File

@ -33,6 +33,7 @@ struct ThreadEntry {
dirty: bool, dirty: bool,
hidden: bool, hidden: bool,
heading: String, heading: String,
timestamp: UnixTimestamp,
} }
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
@ -162,6 +163,26 @@ impl ThreadView {
} }
fn initiate(&mut self, expanded_hash: Option<ThreadNodeHash>, context: &Context) { fn initiate(&mut self, expanded_hash: Option<ThreadNodeHash>, context: &Context) {
#[inline(always)]
fn make_entry(
i: (usize, ThreadNodeHash, usize),
msg_hash: EnvelopeHash,
seen: bool,
timestamp: UnixTimestamp,
) -> ThreadEntry {
let (ind, _, _) = i;
ThreadEntry {
index: i,
indentation: ind,
msg_hash,
seen,
dirty: true,
hidden: false,
heading: String::new(),
timestamp,
}
}
let account = &context.accounts[&self.coordinates.0]; let account = &context.accounts[&self.coordinates.0];
let threads = account.collection.get_threads(self.coordinates.1); let threads = account.collection.get_threads(self.coordinates.1);
@ -174,8 +195,13 @@ impl ThreadView {
for (line, (ind, thread_node_hash)) in thread_iter.enumerate() { for (line, (ind, thread_node_hash)) in thread_iter.enumerate() {
let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_node_hash].message() let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_node_hash].message()
{ {
let seen: bool = account.collection.get_env(msg_hash).is_seen(); let env_ref = account.collection.get_env(msg_hash);
self.make_entry((ind, thread_node_hash, line), msg_hash, seen) make_entry(
(ind, thread_node_hash, line),
msg_hash,
env_ref.is_seen(),
env_ref.timestamp,
)
} else { } else {
continue; continue;
}; };
@ -189,7 +215,13 @@ impl ThreadView {
} }
} }
if expanded_hash.is_none() { if expanded_hash.is_none() {
self.new_expanded_pos = self.entries.len().saturating_sub(1); self.new_expanded_pos = self
.entries
.iter()
.enumerate()
.reduce(|a, b| if a.1.timestamp > b.1.timestamp { a } else { b })
.map(|el| el.0)
.unwrap_or(0);
self.expanded_pos = self.new_expanded_pos + 1; self.expanded_pos = self.new_expanded_pos + 1;
} }
@ -392,24 +424,6 @@ impl ThreadView {
self.visible_entries = vec![(0..self.entries.len()).collect()]; self.visible_entries = vec![(0..self.entries.len()).collect()];
} }
fn make_entry(
&mut self,
i: (usize, ThreadNodeHash, usize),
msg_hash: EnvelopeHash,
seen: bool,
) -> ThreadEntry {
let (ind, _, _) = i;
ThreadEntry {
index: i,
indentation: ind,
msg_hash,
seen,
dirty: true,
hidden: false,
heading: String::new(),
}
}
fn highlight_line( fn highlight_line(
&self, &self,
grid: &mut CellBuffer, grid: &mut CellBuffer,