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

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/295/head
Manos Pitsidianakis 2023-08-30 10:00:17 +03:00
parent 85af524458
commit 1b3bebe304
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
6 changed files with 32 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -81,6 +81,7 @@ impl ThreadView {
coordinates: (AccountHash, MailboxHash, EnvelopeHash),
thread_group: ThreadHash,
expanded_hash: Option<EnvelopeHash>,
go_to_first_unread: bool,
focus: Option<ThreadViewFocus>,
context: &mut Context,
) -> Self {
@ -105,7 +106,7 @@ impl ThreadView {
use_color: context.settings.terminal.use_color(),
..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
}
@ -130,7 +131,7 @@ impl ThreadView {
};
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 new_cursor = 0;
@ -172,7 +173,12 @@ impl ThreadView {
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)]
fn make_entry(
i: (usize, ThreadNodeHash, usize),
@ -210,11 +216,19 @@ impl ThreadView {
let thread_iter = threads.thread_iter(self.thread_group);
self.entries.clear();
let mut earliest_unread = 0;
let mut earliest_unread_entry = 0;
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 (is_seen, timestamp) = {
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)
};
make_entry(
@ -248,6 +262,10 @@ impl ThreadView {
.unwrap_or(0);
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 mut width = 0;
@ -1105,7 +1123,7 @@ impl Component for ThreadView {
{
self.reversed = !self.reversed;
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;
true
}