ui: insert new envelopes in threads
parent
bcef22b3f3
commit
5135c5ce3f
|
@ -40,6 +40,11 @@ impl Collection {
|
|||
pub fn is_empty(&self) -> bool {
|
||||
self.envelopes.is_empty()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, hash: EnvelopeHash, mut envelope: Envelope) {
|
||||
self.threads.insert(&mut envelope);
|
||||
self.envelopes.insert(hash, envelope);
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Collection {
|
||||
|
|
|
@ -115,7 +115,6 @@ impl Mailbox {
|
|||
pub fn insert(&mut self, envelope: Envelope) -> &Envelope {
|
||||
let hash = envelope.hash();
|
||||
self.collection.insert(hash, envelope);
|
||||
// TODO: Update threads.
|
||||
eprintln!("Inserted envelope");
|
||||
&self.collection[&hash]
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ pub struct Threads {
|
|||
thread_nodes: Vec<ThreadNode>,
|
||||
root_set: Vec<usize>,
|
||||
|
||||
message_ids: FnvHashMap<String, EnvelopeHash>,
|
||||
message_ids: FnvHashMap<String, usize>,
|
||||
sort: RefCell<(SortField, SortOrder)>,
|
||||
subsort: RefCell<(SortField, SortOrder)>,
|
||||
}
|
||||
|
@ -210,12 +210,17 @@ impl Threads {
|
|||
let mut t = Threads {
|
||||
thread_nodes,
|
||||
root_set,
|
||||
message_ids,
|
||||
..Default::default()
|
||||
};
|
||||
t.build_collection(&collection);
|
||||
t
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, envelope: &mut Envelope) {
|
||||
link_envelope(&mut self.thread_nodes, &mut self.message_ids, envelope);
|
||||
}
|
||||
|
||||
fn build_collection(&mut self, collection: &FnvHashMap<EnvelopeHash, Envelope>) {
|
||||
for i in &self.root_set {
|
||||
node_build(
|
||||
|
@ -284,13 +289,12 @@ impl Threads {
|
|||
}
|
||||
}
|
||||
|
||||
fn link_threads(
|
||||
fn link_envelope(
|
||||
thread_nodes: &mut Vec<ThreadNode>,
|
||||
message_ids: &mut FnvHashMap<String, usize>,
|
||||
collection: &mut FnvHashMap<EnvelopeHash, Envelope>,
|
||||
envelope: &mut Envelope,
|
||||
) {
|
||||
for (k, v) in collection.iter_mut() {
|
||||
let m_id = v.message_id_raw().to_string();
|
||||
let m_id = envelope.message_id_raw().to_string();
|
||||
|
||||
/* The index of this message's ThreadNode in thread_nodes */
|
||||
|
||||
|
@ -300,21 +304,21 @@ fn link_threads(
|
|||
* seeing this message for the first time. otherwise it's a
|
||||
* duplicate. */
|
||||
if thread_nodes[node_idx].message.is_some() {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
thread_nodes[node_idx].date = v.date();
|
||||
thread_nodes[node_idx].message = Some(*k);
|
||||
v.set_thread(node_idx);
|
||||
thread_nodes[node_idx].date = envelope.date();
|
||||
thread_nodes[node_idx].message = Some(envelope.hash());
|
||||
envelope.set_thread(node_idx);
|
||||
|
||||
node_idx
|
||||
} else {
|
||||
/* Create a new ThreadNode object holding this message */
|
||||
thread_nodes.push(ThreadNode {
|
||||
message: Some(*k),
|
||||
date: v.date(),
|
||||
message: Some(envelope.hash()),
|
||||
date: envelope.date(),
|
||||
..Default::default()
|
||||
});
|
||||
v.set_thread(thread_nodes.len() - 1);
|
||||
envelope.set_thread(thread_nodes.len() - 1);
|
||||
message_ids.insert(m_id, thread_nodes.len() - 1);
|
||||
thread_nodes.len() - 1
|
||||
};
|
||||
|
@ -339,7 +343,7 @@ fn link_threads(
|
|||
let mut ref_ptr = t_idx;
|
||||
|
||||
let mut iasf = 0;
|
||||
for &refn in v.references().iter().rev() {
|
||||
for &refn in envelope.references().iter().rev() {
|
||||
if iasf == 1 {
|
||||
/*FIXME: Skips anything other than direct parents */
|
||||
continue;
|
||||
|
@ -372,7 +376,7 @@ fn link_threads(
|
|||
thread_nodes.push(ThreadNode {
|
||||
message: None,
|
||||
children: vec![ref_ptr; 1],
|
||||
date: v.date(),
|
||||
date: envelope.date(),
|
||||
..Default::default()
|
||||
});
|
||||
if thread_nodes[ref_ptr].parent.is_none() {
|
||||
|
@ -387,8 +391,8 @@ fn link_threads(
|
|||
let mut parent_iter = parent_id;
|
||||
'date: loop {
|
||||
let p: &mut ThreadNode = &mut thread_nodes[parent_iter];
|
||||
if p.date < v.date() {
|
||||
p.date = v.date();
|
||||
if p.date < envelope.date() {
|
||||
p.date = envelope.date();
|
||||
}
|
||||
if let Some(p) = p.parent {
|
||||
parent_iter = p;
|
||||
|
@ -398,6 +402,15 @@ fn link_threads(
|
|||
}
|
||||
ref_ptr = parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
fn link_threads(
|
||||
thread_nodes: &mut Vec<ThreadNode>,
|
||||
message_ids: &mut FnvHashMap<String, usize>,
|
||||
collection: &mut FnvHashMap<EnvelopeHash, Envelope>,
|
||||
) {
|
||||
for v in collection.values_mut() {
|
||||
link_envelope(thread_nodes, message_ids, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue