Some listing refactoring
parent
f58ed387dd
commit
0ac10aa4d0
|
@ -141,6 +141,9 @@ pub trait MailListingTrait: ListingTrait {
|
|||
|
||||
fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]>;
|
||||
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]>;
|
||||
fn redraw_list(&mut self, context: &Context, items: Box<dyn Iterator<Item = ThreadHash>>) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ListingTrait: Component {
|
||||
|
|
|
@ -469,7 +469,11 @@ impl ListingTrait for CompactListing {
|
|||
self.data_columns.columns[0] =
|
||||
CellBuffer::new_with_context(0, 0, Cell::with_char(' '), context);
|
||||
}
|
||||
self.redraw_list(context);
|
||||
self.redraw_list(
|
||||
context,
|
||||
Box::new(self.filtered_selection.clone().into_iter())
|
||||
as Box<dyn Iterator<Item = ThreadHash>>,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
self.cursor_pos.2 = 0;
|
||||
|
@ -545,9 +549,13 @@ impl CompactListing {
|
|||
&self,
|
||||
e: &Envelope,
|
||||
context: &Context,
|
||||
thread_node: &ThreadNode,
|
||||
is_snoozed: bool,
|
||||
threads: &Threads,
|
||||
hash: ThreadHash,
|
||||
) -> EntryStrings {
|
||||
let is_snoozed: bool = threads.is_snoozed(hash);
|
||||
let date =
|
||||
threads.thread_dates[&melib::thread::find_thread_group(threads.thread_nodes(), hash)];
|
||||
let thread_node = &threads[&hash];
|
||||
let folder_hash = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
|
||||
.unwrap()
|
||||
.folder
|
||||
|
@ -591,7 +599,7 @@ impl CompactListing {
|
|||
subject.truncate_at_boundary(150);
|
||||
if thread_node.len() > 0 {
|
||||
EntryStrings {
|
||||
date: DateString(ConversationsListing::format_date(context, thread_node)),
|
||||
date: DateString(ConversationsListing::format_date(context, date)),
|
||||
subject: SubjectString(format!("{} ({})", subject, thread_node.len(),)),
|
||||
flag: FlagString(format!(
|
||||
"{}{}",
|
||||
|
@ -603,7 +611,7 @@ impl CompactListing {
|
|||
}
|
||||
} else {
|
||||
EntryStrings {
|
||||
date: DateString(ConversationsListing::format_date(context, thread_node)),
|
||||
date: DateString(ConversationsListing::format_date(context, date)),
|
||||
subject: SubjectString(subject),
|
||||
flag: FlagString(format!(
|
||||
"{}{}",
|
||||
|
@ -667,10 +675,22 @@ impl CompactListing {
|
|||
self.view = ThreadView::new(self.new_cursor_pos, None, context);
|
||||
}
|
||||
|
||||
self.redraw_list(context);
|
||||
let threads = &context.accounts[self.cursor_pos.0].collection.threads[&folder_hash];
|
||||
threads.sort_by(
|
||||
self.sort,
|
||||
self.subsort,
|
||||
&context.accounts[self.cursor_pos.0].collection.envelopes,
|
||||
);
|
||||
self.all_threads.clear();
|
||||
|
||||
self.redraw_list(
|
||||
context,
|
||||
Box::new(threads.root_iter().collect::<Vec<ThreadHash>>().into_iter())
|
||||
as Box<dyn Iterator<Item = ThreadHash>>,
|
||||
);
|
||||
}
|
||||
|
||||
fn redraw_list(&mut self, context: &Context) {
|
||||
fn redraw_list(&mut self, context: &Context, items: Box<dyn Iterator<Item = ThreadHash>>) {
|
||||
let account = &context.accounts[self.cursor_pos.0];
|
||||
let mailbox = &account[self.cursor_pos.1].unwrap();
|
||||
|
||||
|
@ -694,18 +714,7 @@ impl CompactListing {
|
|||
SmallVec::new(),
|
||||
);
|
||||
|
||||
threads.sort_by(self.sort, self.subsort, &account.collection.envelopes);
|
||||
|
||||
let mut refresh_mailbox = false;
|
||||
let threads_iter = if self.filter_term.is_empty() {
|
||||
refresh_mailbox = true;
|
||||
self.all_threads.clear();
|
||||
Box::new(threads.root_iter()) as Box<dyn Iterator<Item = ThreadHash>>
|
||||
} else {
|
||||
Box::new(self.filtered_selection.iter().map(|h| *h))
|
||||
as Box<dyn Iterator<Item = ThreadHash>>
|
||||
};
|
||||
for (idx, root_idx) in threads_iter.enumerate() {
|
||||
for (idx, root_idx) in items.enumerate() {
|
||||
self.length += 1;
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
|
@ -729,12 +738,7 @@ impl CompactListing {
|
|||
let root_envelope: EnvelopeRef =
|
||||
context.accounts[self.cursor_pos.0].collection.get_env(i);
|
||||
|
||||
let entry_strings = self.make_entry_string(
|
||||
&root_envelope,
|
||||
context,
|
||||
thread_node,
|
||||
threads.is_snoozed(root_idx),
|
||||
);
|
||||
let entry_strings = self.make_entry_string(&root_envelope, context, threads, root_idx);
|
||||
row_widths.1.push(
|
||||
entry_strings
|
||||
.date
|
||||
|
@ -768,10 +772,8 @@ impl CompactListing {
|
|||
min_width.4,
|
||||
entry_strings.subject.grapheme_width() + 1 + entry_strings.tags.grapheme_width(),
|
||||
); /* subject */
|
||||
rows.push(entry_strings);
|
||||
if refresh_mailbox {
|
||||
self.all_threads.insert(root_idx);
|
||||
}
|
||||
rows.push(((idx, root_idx), entry_strings));
|
||||
self.all_threads.insert(root_idx);
|
||||
|
||||
self.order.insert(root_idx, idx);
|
||||
self.selection.insert(root_idx, false);
|
||||
|
@ -797,14 +799,8 @@ impl CompactListing {
|
|||
self.data_columns.columns[4] =
|
||||
CellBuffer::new_with_context(min_width.4, rows.len(), Cell::with_char(' '), context);
|
||||
self.data_columns.segment_tree[4] = row_widths.4.into();
|
||||
let threads_iter = if self.filter_term.is_empty() {
|
||||
Box::new(threads.root_iter()) as Box<dyn Iterator<Item = ThreadHash>>
|
||||
} else {
|
||||
Box::new(self.filtered_selection.iter().map(|h| *h))
|
||||
as Box<dyn Iterator<Item = ThreadHash>>
|
||||
};
|
||||
|
||||
for ((idx, root_idx), strings) in threads_iter.enumerate().zip(rows) {
|
||||
for ((idx, root_idx), strings) in rows {
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
|
@ -975,11 +971,19 @@ impl CompactListing {
|
|||
}
|
||||
|
||||
fn get_thread_under_cursor(&self, cursor: usize, context: &Context) -> ThreadHash {
|
||||
let account = &context.accounts[self.cursor_pos.0];
|
||||
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||
let threads = &account.collection.threads[&folder_hash];
|
||||
//let account = &context.accounts[self.cursor_pos.0];
|
||||
//let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||
if self.filter_term.is_empty() {
|
||||
threads.root_set(cursor)
|
||||
*self
|
||||
.order
|
||||
.iter()
|
||||
.find(|(_, &r)| r == cursor)
|
||||
.unwrap_or_else(|| {
|
||||
debug!("self.order empty ? cursor={} {:#?}", cursor, &self.order);
|
||||
panic!();
|
||||
})
|
||||
.0
|
||||
//threads.root_set(cursor)
|
||||
} else {
|
||||
self.filtered_selection[cursor]
|
||||
}
|
||||
|
@ -1020,12 +1024,7 @@ impl CompactListing {
|
|||
Color::Default
|
||||
}
|
||||
};
|
||||
let strings = self.make_entry_string(
|
||||
&envelope,
|
||||
context,
|
||||
&threads[&thread_hash],
|
||||
threads.is_snoozed(thread_hash),
|
||||
);
|
||||
let strings = self.make_entry_string(&envelope, context, threads, thread_hash);
|
||||
drop(envelope);
|
||||
let columns = &mut self.data_columns.columns;
|
||||
let min_width = (
|
||||
|
|
|
@ -562,7 +562,10 @@ impl ConversationsListing {
|
|||
subject.truncate_at_boundary(150);
|
||||
if thread_node.len() > 0 {
|
||||
EntryStrings {
|
||||
date: DateString(ConversationsListing::format_date(context, thread_node)),
|
||||
date: DateString(ConversationsListing::format_date(
|
||||
context,
|
||||
thread_node.date(),
|
||||
)),
|
||||
subject: SubjectString(format!("{} ({})", subject, thread_node.len(),)),
|
||||
flag: FlagString(format!(
|
||||
"{}{}",
|
||||
|
@ -574,7 +577,10 @@ impl ConversationsListing {
|
|||
}
|
||||
} else {
|
||||
EntryStrings {
|
||||
date: DateString(ConversationsListing::format_date(context, thread_node)),
|
||||
date: DateString(ConversationsListing::format_date(
|
||||
context,
|
||||
thread_node.date(),
|
||||
)),
|
||||
subject: SubjectString(subject),
|
||||
flag: FlagString(format!(
|
||||
"{}{}",
|
||||
|
@ -890,8 +896,8 @@ impl ConversationsListing {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn format_date(context: &Context, thread_node: &ThreadNode) -> String {
|
||||
let d = std::time::UNIX_EPOCH + std::time::Duration::from_secs(thread_node.date());
|
||||
pub(super) fn format_date(context: &Context, epoch: UnixTimestamp) -> String {
|
||||
let d = std::time::UNIX_EPOCH + std::time::Duration::from_secs(epoch);
|
||||
let now: std::time::Duration = std::time::SystemTime::now()
|
||||
.duration_since(d)
|
||||
.unwrap_or_else(|_| std::time::Duration::new(std::u64::MAX, 0));
|
||||
|
@ -912,7 +918,7 @@ impl ConversationsListing {
|
|||
if n / (24 * 60 * 60) == 1 { "" } else { "s" }
|
||||
),
|
||||
_ => melib::datetime::timestamp_to_string(
|
||||
thread_node.date(),
|
||||
epoch,
|
||||
context
|
||||
.settings
|
||||
.listing
|
||||
|
@ -925,11 +931,20 @@ impl ConversationsListing {
|
|||
}
|
||||
|
||||
fn get_thread_under_cursor(&self, cursor: usize, context: &Context) -> ThreadHash {
|
||||
let account = &context.accounts[self.cursor_pos.0];
|
||||
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||
let threads = &account.collection.threads[&folder_hash];
|
||||
//let account = &context.accounts[self.cursor_pos.0];
|
||||
//let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
|
||||
//let threads = &account.collection.threads[&folder_hash];
|
||||
if self.filter_term.is_empty() {
|
||||
threads.root_set(cursor)
|
||||
*self
|
||||
.order
|
||||
.iter()
|
||||
.find(|(_, &r)| r == cursor)
|
||||
.unwrap_or_else(|| {
|
||||
debug!("self.order empty ? cursor={} {:#?}", cursor, &self.order);
|
||||
panic!();
|
||||
})
|
||||
.0
|
||||
//threads.root_set(cursor)
|
||||
} else {
|
||||
self.filtered_selection[cursor]
|
||||
}
|
||||
|
|
|
@ -418,19 +418,21 @@ impl Component for MailView {
|
|||
format!("Subject: {}", envelope.subject())
|
||||
format!("Message-ID: <{}>", envelope.message_id_raw())
|
||||
);
|
||||
if self.expand_headers && envelope.in_reply_to().is_some() {
|
||||
print_header!(
|
||||
format!("In-Reply-To: {}", envelope.in_reply_to_display().unwrap())
|
||||
format!(
|
||||
"References: {}",
|
||||
envelope
|
||||
.references()
|
||||
.iter()
|
||||
.map(std::string::ToString::to_string)
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
);
|
||||
if self.expand_headers {
|
||||
if let Some(val) = envelope.in_reply_to_display() {
|
||||
print_header!(
|
||||
format!("In-Reply-To: {}", val)
|
||||
format!(
|
||||
"References: {}",
|
||||
envelope
|
||||
.references()
|
||||
.iter()
|
||||
.map(std::string::ToString::to_string)
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(list_management::ListActions {
|
||||
ref id,
|
||||
|
|
Loading…
Reference in New Issue