summaryrefslogtreecommitdiffstats
path: root/melib/src
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-01 23:53:06 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:41 +0300
commit11b2abd1d125a41a0fb0c28a166316f6aed5bc39 (patch)
treeddf88e2499d8445eb493230e81b163af648c0a8b /melib/src
parentf36cb111b5b16614eb0b7930cb342d60bdec6f31 (diff)
ui: fix seen property of threads on open, add env rename events
Diffstat (limited to 'melib/src')
-rw-r--r--melib/src/mailbox/collection.rs4
-rw-r--r--melib/src/mailbox/thread.rs34
2 files changed, 31 insertions, 7 deletions
diff --git a/melib/src/mailbox/collection.rs b/melib/src/mailbox/collection.rs
index 54ffaaa3..9dffab4b 100644
--- a/melib/src/mailbox/collection.rs
+++ b/melib/src/mailbox/collection.rs
@@ -107,7 +107,7 @@ impl Collection {
env.set_hash(new_hash);
self.envelopes.insert(new_hash, env);
{
- if self.threads.update_envelope(old_hash, new_hash).is_ok() {
+ if self.threads.update_envelope(old_hash, new_hash, &self.envelopes).is_ok() {
return;
}
}
@@ -123,7 +123,7 @@ impl Collection {
let new_hash = envelope.hash();
self.envelopes.insert(new_hash, envelope);
{
- if self.threads.update_envelope(old_hash, new_hash).is_ok() {
+ if self.threads.update_envelope(old_hash, new_hash, &self.envelopes).is_ok() {
return;
}
}
diff --git a/melib/src/mailbox/thread.rs b/melib/src/mailbox/thread.rs
index b4427b01..8e86b842 100644
--- a/melib/src/mailbox/thread.rs
+++ b/melib/src/mailbox/thread.rs
@@ -822,22 +822,26 @@ impl Threads {
&mut self,
old_hash: EnvelopeHash,
new_hash: EnvelopeHash,
+ collection: &Envelopes,
) -> Result<(), ()> {
/* must update:
* - hash_set
* - message fields in thread_nodes
*/
- self.hash_set.remove(&old_hash);
- if let Some(node) = self
+ let idx = if let Some((idx, node)) = self
.thread_nodes
.iter_mut()
- .find(|n| n.message.map(|n| n == old_hash).unwrap_or(false))
+ .enumerate()
+ .find(|(_, n)| n.message.map(|n| n == old_hash).unwrap_or(false))
{
node.message = Some(new_hash);
+ idx
} else {
return Err(());
- }
+ };
+ self.hash_set.remove(&old_hash);
self.hash_set.insert(new_hash);
+ self.rebuild_thread(idx, collection);
Ok(())
}
@@ -971,6 +975,26 @@ impl Threads {
let mut node_idx = id;
let mut stack = Vec::with_capacity(32);
+ let no_parent: bool = if let Some(node) = self.thread_nodes.get(node_idx) {
+ if node.parent.is_none() {
+ true
+ } else {
+ false
+ }
+ } else {
+ false
+ };
+
+ if no_parent {
+ let tree = self.tree.get_mut();
+ if let Some(tree) = tree.iter_mut().find(|t| t.id == id) {
+ *tree = ThreadTree::new(id);
+ node_build(tree, id, &mut self.thread_nodes, 1, collection);
+ return;
+ }
+ unreachable!();
+ }
+
/* Trace path back to root ThreadNode */
while let Some(p) = &self.thread_nodes[node_idx].parent {
node_idx = *p;
@@ -1310,7 +1334,7 @@ fn node_build(
indentation + 1
};
- let mut has_unseen = thread_nodes[idx].has_unseen;
+ let mut has_unseen = !collection[&thread_nodes[idx].message.unwrap()].is_seen();
let mut child_vec: Vec<ThreadTree> = Vec::new();
thread_nodes[idx].len = thread_nodes[idx].children.len();