melib/ui: print threads in correct order
parent
630330f632
commit
8c5879032e
|
@ -96,26 +96,27 @@ impl ThreadTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ThreadIterator<'a> {
|
pub struct ThreadIterator<'a> {
|
||||||
|
init_pos: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
stack: Vec<usize>,
|
stack: Vec<usize>,
|
||||||
tree: Ref<'a, Vec<ThreadTree>>,
|
tree: Ref<'a, Vec<ThreadTree>>,
|
||||||
}
|
}
|
||||||
impl<'a> Iterator for ThreadIterator<'a> {
|
impl<'a> Iterator for ThreadIterator<'a> {
|
||||||
type Item = usize;
|
type Item = (usize, usize);
|
||||||
fn next(&mut self) -> Option<usize> {
|
fn next(&mut self) -> Option<(usize, usize)> {
|
||||||
{
|
{
|
||||||
let mut tree = &(*self.tree);
|
let mut tree = &(*self.tree);
|
||||||
for i in &self.stack {
|
for i in self.stack.iter() {
|
||||||
tree = &tree[*i].children;
|
tree = &tree[*i].children;
|
||||||
}
|
}
|
||||||
if self.pos == tree.len() {
|
if self.pos == tree.len() || (self.stack.is_empty() && self.pos > self.init_pos) {
|
||||||
if self.stack.is_empty() {
|
if self.stack.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
self.pos = self.stack.pop().unwrap() + 1;
|
self.pos = self.stack.pop().unwrap() + 1;
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(self.pos < tree.len());
|
debug_assert!(self.pos < tree.len());
|
||||||
let ret = tree[self.pos].id;
|
let ret = (self.stack.len(), tree[self.pos].id);
|
||||||
if !tree[self.pos].children.is_empty() {
|
if !tree[self.pos].children.is_empty() {
|
||||||
self.stack.push(self.pos);
|
self.stack.push(self.pos);
|
||||||
self.pos = 0;
|
self.pos = 0;
|
||||||
|
@ -231,18 +232,18 @@ impl PartialEq for ThreadNode {
|
||||||
|
|
||||||
pub struct RootIterator<'a> {
|
pub struct RootIterator<'a> {
|
||||||
pos: usize,
|
pos: usize,
|
||||||
root_set: Ref<'a, Vec<usize>>,
|
root_tree: Ref<'a, Vec<ThreadTree>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for RootIterator<'a> {
|
impl<'a> Iterator for RootIterator<'a> {
|
||||||
type Item = usize;
|
type Item = usize;
|
||||||
fn next(&mut self) -> Option<usize> {
|
fn next(&mut self) -> Option<usize> {
|
||||||
{
|
{
|
||||||
if self.pos == self.root_set.len() {
|
if self.pos == self.root_tree.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
return Some(self.root_set[self.pos - 1]);
|
return Some(self.root_tree[self.pos - 1].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,6 +302,8 @@ impl Threads {
|
||||||
root_set: RefCell::new(root_set),
|
root_set: RefCell::new(root_set),
|
||||||
message_ids,
|
message_ids,
|
||||||
hash_set,
|
hash_set,
|
||||||
|
subsort: RefCell::new((SortField::Subject, SortOrder::Desc)),
|
||||||
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
t.build_collection(&collection);
|
t.build_collection(&collection);
|
||||||
|
@ -309,6 +312,7 @@ impl Threads {
|
||||||
|
|
||||||
pub fn thread_iter(&self, index: usize) -> ThreadIterator {
|
pub fn thread_iter(&self, index: usize) -> ThreadIterator {
|
||||||
ThreadIterator {
|
ThreadIterator {
|
||||||
|
init_pos: index,
|
||||||
pos: index,
|
pos: index,
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
tree: self.tree.borrow(),
|
tree: self.tree.borrow(),
|
||||||
|
@ -470,13 +474,13 @@ impl Threads {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_set(&self, idx: usize) -> usize {
|
pub fn root_set(&self, idx: usize) -> usize {
|
||||||
self.root_set.borrow()[idx]
|
self.tree.borrow()[idx].id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_iter<'a>(&'a self) -> RootIterator<'a> {
|
pub fn root_iter<'a>(&'a self) -> RootIterator<'a> {
|
||||||
RootIterator {
|
RootIterator {
|
||||||
pos: 0,
|
pos: 0,
|
||||||
root_set: self.root_set.borrow(),
|
root_tree: self.tree.borrow(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl CompactListing {
|
||||||
new_cursor_pos: (0, 0, 0),
|
new_cursor_pos: (0, 0, 0),
|
||||||
length: 0,
|
length: 0,
|
||||||
sort: (Default::default(), Default::default()),
|
sort: (Default::default(), Default::default()),
|
||||||
subsort: (Default::default(), Default::default()),
|
subsort: (SortField::Subject, SortOrder::Desc),
|
||||||
content,
|
content,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
unfocused: false,
|
unfocused: false,
|
||||||
|
|
|
@ -58,20 +58,12 @@ impl ThreadView {
|
||||||
context: &Context,
|
context: &Context,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
/* stack to push thread messages in order in order to pop and print them later */
|
/* stack to push thread messages in order in order to pop and print them later */
|
||||||
let mut stack: Vec<(usize, usize)> = Vec::with_capacity(32);
|
|
||||||
let mailbox = &context.accounts[coordinates.0][coordinates.1]
|
let mailbox = &context.accounts[coordinates.0][coordinates.1]
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let threads = &mailbox.collection.threads;
|
let threads = &mailbox.collection.threads;
|
||||||
let thread_node = &threads.thread_nodes()[threads.root_set(coordinates.2)];
|
|
||||||
|
|
||||||
if thread_node.message().is_some() {
|
let thread_iter = threads.thread_iter(coordinates.2);
|
||||||
stack.push((0, threads.root_set(coordinates.2)));
|
|
||||||
} else {
|
|
||||||
for &c in thread_node.children().iter() {
|
|
||||||
stack.push((1, c));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut view = ThreadView {
|
let mut view = ThreadView {
|
||||||
dirty: true,
|
dirty: true,
|
||||||
initiated: false,
|
initiated: false,
|
||||||
|
@ -84,10 +76,12 @@ impl ThreadView {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let mut line = 0;
|
let mut line = 0;
|
||||||
let mut max_ind = 0;
|
for (ind, idx) in thread_iter {
|
||||||
while let Some((ind, idx)) = stack.pop() {
|
let entry = if let Some(msg_idx) = threads.thread_nodes()[idx].message() {
|
||||||
max_ind = cmp::max(max_ind, ind);
|
view.make_entry((ind, idx, line), msg_idx)
|
||||||
let entry = view.make_entry(context, (ind, idx, line));
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
view.entries.push(entry);
|
view.entries.push(entry);
|
||||||
line += 1;
|
line += 1;
|
||||||
match expanded_idx {
|
match expanded_idx {
|
||||||
|
@ -97,10 +91,6 @@ impl ThreadView {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
let thread_node = &threads.thread_nodes()[idx];
|
|
||||||
for &c in thread_node.children().iter() {
|
|
||||||
stack.push((ind + 1, c));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if expanded_idx.is_none() {
|
if expanded_idx.is_none() {
|
||||||
view.new_expanded_pos = view.entries.len().saturating_sub(1);
|
view.new_expanded_pos = view.entries.len().saturating_sub(1);
|
||||||
|
@ -191,22 +181,10 @@ impl ThreadView {
|
||||||
view
|
view
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_entry(&mut self, context: &Context, i: (usize, usize, usize)) -> ThreadEntry {
|
fn make_entry(&mut self, i: (usize, usize, usize), msg_idx: EnvelopeHash) -> ThreadEntry {
|
||||||
let (ind, idx, order) = i;
|
let (ind, _, _) = i;
|
||||||
let mailbox = &context.accounts[self.coordinates.0][self.coordinates.1]
|
|
||||||
.as_ref()
|
|
||||||
.unwrap();
|
|
||||||
let thread_node = &mailbox.collection.threads.thread_nodes()[idx];
|
|
||||||
let msg_idx = if let Some(i) = thread_node.message() {
|
|
||||||
i
|
|
||||||
} else {
|
|
||||||
mailbox.collection.threads.thread_nodes()[thread_node.children()[0]]
|
|
||||||
.message()
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
ThreadEntry {
|
ThreadEntry {
|
||||||
index: (ind, idx, order),
|
index: i,
|
||||||
indentation: ind,
|
indentation: ind,
|
||||||
msg_idx,
|
msg_idx,
|
||||||
}
|
}
|
||||||
|
@ -438,9 +416,11 @@ impl ThreadView {
|
||||||
let i = if let Some(i) = thread_node.message() {
|
let i = if let Some(i) = thread_node.message() {
|
||||||
i
|
i
|
||||||
} else {
|
} else {
|
||||||
threads.thread_nodes()[thread_node.children()[0]]
|
let mut iter_ptr = thread_node.children()[0];
|
||||||
.message()
|
while threads.thread_nodes()[iter_ptr].message().is_none() {
|
||||||
.unwrap()
|
iter_ptr = threads.thread_nodes()[iter_ptr].children()[0];
|
||||||
|
}
|
||||||
|
threads.thread_nodes()[iter_ptr].message().unwrap()
|
||||||
};
|
};
|
||||||
let envelope: &Envelope = &mailbox.collection[&i];
|
let envelope: &Envelope = &mailbox.collection[&i];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue