view/thread: open earliest unread email instead of first in thread

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/295/head
Manos Pitsidianakis 10 months ago
parent 85af524458
commit 1b3bebe304
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -1308,6 +1308,7 @@ impl Component for Listing {
env_hash, env_hash,
thread_hash, thread_hash,
show_thread, show_thread,
go_to_first_unread,
}) => { }) => {
let (a, m) = self.component.coordinates(); let (a, m) = self.component.coordinates();
self.view.unrealize(context); self.view.unrealize(context);
@ -1315,6 +1316,7 @@ impl Component for Listing {
(a, m, env_hash), (a, m, env_hash),
thread_hash, thread_hash,
Some(env_hash), Some(env_hash),
go_to_first_unread,
if show_thread { if show_thread {
None None
} else { } else {
@ -3068,6 +3070,7 @@ pub enum ListingMessage {
env_hash: EnvelopeHash, env_hash: EnvelopeHash,
thread_hash: ThreadHash, thread_hash: ThreadHash,
show_thread: bool, show_thread: bool,
go_to_first_unread: bool,
}, },
UpdateView, UpdateView,
} }

@ -331,6 +331,7 @@ impl MailListingTrait for CompactListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: true, show_thread: true,
go_to_first_unread: true,
}, },
context, context,
); );
@ -930,6 +931,7 @@ impl ListingTrait for CompactListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: true, show_thread: true,
go_to_first_unread: true,
}, },
context, context,
); );

@ -238,6 +238,7 @@ impl MailListingTrait for ConversationsListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: true, show_thread: true,
go_to_first_unread: true,
}, },
context, context,
); );
@ -666,6 +667,7 @@ impl ListingTrait for ConversationsListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: true, show_thread: true,
go_to_first_unread: true,
}, },
context, context,
); );

@ -297,6 +297,7 @@ impl MailListingTrait for PlainListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: false, show_thread: false,
go_to_first_unread: false,
}, },
context, context,
); );
@ -648,6 +649,7 @@ impl ListingTrait for PlainListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: false, show_thread: false,
go_to_first_unread: false,
}, },
context, context,
); );

@ -730,6 +730,7 @@ impl ListingTrait for ThreadListing {
thread_hash, thread_hash,
env_hash, env_hash,
show_thread: false, show_thread: false,
go_to_first_unread: false,
}, },
context, context,
); );

@ -81,6 +81,7 @@ impl ThreadView {
coordinates: (AccountHash, MailboxHash, EnvelopeHash), coordinates: (AccountHash, MailboxHash, EnvelopeHash),
thread_group: ThreadHash, thread_group: ThreadHash,
expanded_hash: Option<EnvelopeHash>, expanded_hash: Option<EnvelopeHash>,
go_to_first_unread: bool,
focus: Option<ThreadViewFocus>, focus: Option<ThreadViewFocus>,
context: &mut Context, context: &mut Context,
) -> Self { ) -> Self {
@ -105,7 +106,7 @@ impl ThreadView {
use_color: context.settings.terminal.use_color(), use_color: context.settings.terminal.use_color(),
..Default::default() ..Default::default()
}; };
view.initiate(expanded_hash, context); view.initiate(expanded_hash, go_to_first_unread, context);
view.new_cursor_pos = view.new_expanded_pos; view.new_cursor_pos = view.new_expanded_pos;
view view
} }
@ -130,7 +131,7 @@ impl ThreadView {
}; };
let expanded_hash = old_expanded_entry.as_ref().map(|e| e.msg_hash); let expanded_hash = old_expanded_entry.as_ref().map(|e| e.msg_hash);
self.initiate(expanded_hash, context); self.initiate(expanded_hash, false, context);
let mut old_cursor = 0; let mut old_cursor = 0;
let mut new_cursor = 0; let mut new_cursor = 0;
@ -172,7 +173,12 @@ impl ThreadView {
self.set_dirty(true); self.set_dirty(true);
} }
fn initiate(&mut self, expanded_hash: Option<EnvelopeHash>, context: &mut Context) { fn initiate(
&mut self,
expanded_hash: Option<EnvelopeHash>,
go_to_first_unread: bool,
context: &mut Context,
) {
#[inline(always)] #[inline(always)]
fn make_entry( fn make_entry(
i: (usize, ThreadNodeHash, usize), i: (usize, ThreadNodeHash, usize),
@ -210,11 +216,19 @@ impl ThreadView {
let thread_iter = threads.thread_iter(self.thread_group); let thread_iter = threads.thread_iter(self.thread_group);
self.entries.clear(); self.entries.clear();
let mut earliest_unread = 0;
let mut earliest_unread_entry = 0;
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 (is_seen, timestamp) = { let (is_seen, timestamp) = {
let env_ref = collection.get_env(msg_hash); let env_ref = collection.get_env(msg_hash);
if !env_ref.is_seen()
&& (earliest_unread == 0 || env_ref.timestamp < earliest_unread)
{
earliest_unread = env_ref.timestamp;
earliest_unread_entry = self.entries.len();
}
(env_ref.is_seen(), env_ref.timestamp) (env_ref.is_seen(), env_ref.timestamp)
}; };
make_entry( make_entry(
@ -248,6 +262,10 @@ impl ThreadView {
.unwrap_or(0); .unwrap_or(0);
self.expanded_pos = self.new_expanded_pos + 1; self.expanded_pos = self.new_expanded_pos + 1;
} }
if go_to_first_unread && earliest_unread > 0 {
self.new_expanded_pos = earliest_unread_entry;
self.expanded_pos = earliest_unread_entry + 1;
}
let height = 2 * self.entries.len() + 1; let height = 2 * self.entries.len() + 1;
let mut width = 0; let mut width = 0;
@ -1105,7 +1123,7 @@ impl Component for ThreadView {
{ {
self.reversed = !self.reversed; self.reversed = !self.reversed;
let expanded_hash = self.entries[self.expanded_pos].msg_hash; let expanded_hash = self.entries[self.expanded_pos].msg_hash;
self.initiate(Some(expanded_hash), context); self.initiate(Some(expanded_hash), false, context);
self.dirty = true; self.dirty = true;
true true
} }

Loading…
Cancel
Save