From a655a85b5fed4bb483044d09214e20186f343b9b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 6 Jul 2019 12:46:45 +0300 Subject: [PATCH] ui: fix replies not being synced and inserted properly on RefreshEvents --- melib/src/collection.rs | 23 ++++++++++++++++++ melib/src/thread.rs | 29 ++--------------------- ui/src/components/mail/listing/compact.rs | 2 +- ui/src/conf/accounts.rs | 3 +-- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/melib/src/collection.rs b/melib/src/collection.rs index 3ae8c2149..ba2a9d525 100644 --- a/melib/src/collection.rs +++ b/melib/src/collection.rs @@ -72,6 +72,12 @@ impl Collection { .entry(folder_hash) .or_default() .remove(envelope_hash, &mut self.envelopes); + for (h, t) in self.threads.iter_mut() { + if *h == folder_hash { + continue; + } + t.remove(envelope_hash, &mut self.envelopes); + } } pub fn rename( @@ -107,6 +113,14 @@ impl Collection { .or_default() .insert(&mut (*env), &self.envelopes); } + for (h, t) in self.threads.iter_mut() { + if *h == folder_hash { + continue; + } + t.update_envelope(old_hash, new_hash, &self.envelopes) + .ok() + .take(); + } } pub fn merge( @@ -207,6 +221,14 @@ impl Collection { .or_default() .insert(&mut (*env), &self.envelopes); } + for (h, t) in self.threads.iter_mut() { + if *h == folder_hash { + continue; + } + t.update_envelope(old_hash, new_hash, &self.envelopes) + .ok() + .take(); + } } pub fn insert(&mut self, envelope: Envelope, folder_hash: FolderHash) -> &Envelope { @@ -221,6 +243,7 @@ impl Collection { &self.envelopes[&hash] } pub fn insert_reply(&mut self, env_hash: EnvelopeHash) { + debug_assert!(self.envelopes.contains_key(&env_hash)); for (_, t) in self.threads.iter_mut() { t.insert_reply(&mut self.envelopes, env_hash); } diff --git a/melib/src/thread.rs b/melib/src/thread.rs index c0e87cb9e..9a97150ea 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -1028,6 +1028,7 @@ impl Threads { self.rebuild_thread(reply_to_id, envelopes); true } else { + /* let new_id = ThreadHash::new(); self.thread_nodes.insert( new_id, @@ -1047,35 +1048,9 @@ impl Threads { envelopes.get_mut(&env_hash).unwrap().set_thread(new_id); self.hash_set.insert(env_hash); self.rebuild_thread(new_id, envelopes); + */ false } - /* - { - if let Some(in_reply_to) = envelope.in_reply_to() { - if !self.message_ids.contains_key(in_reply_to.raw()) { - return false; - } - } else { - return false; - } - } - let hash: EnvelopeHash = envelope.hash(); - envelopes.insert(hash, envelope.clone()); - { - let envelope = envelopes.entry(hash).or_default() as *mut Envelope; - unsafe { - /* Safe because insert only changes envelope's fields and nothing more */ - self.insert(&mut (*envelope), &envelopes); - } - } - let envelope: &Envelope = &envelopes[&hash]; - { - let in_reply_to = envelope.in_reply_to().unwrap().raw(); - let parent_id = self.message_ids[in_reply_to]; - self.rebuild_thread(parent_id, envelopes); - } - true - */ } /* Update thread tree information on envelope insertion */ diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 6514ca51e..6bd5cb279 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -1121,7 +1121,7 @@ impl Component for CompactListing { self.row_updates.push(*new_hash); } else { - /* Listing has was updated in time before the event */ + /* Listing was updated in time before the event */ } self.view .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context); diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 4fe634976..52cc9a241 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -315,6 +315,7 @@ impl Account { let env_hash = envelope.hash(); let mailbox = mailbox!(&folder_hash, self.folders); mailbox.insert(env_hash); + self.collection.insert(*envelope, folder_hash); if self .sent_folder .as_ref() @@ -322,8 +323,6 @@ impl Account { .unwrap_or(false) { self.collection.insert_reply(env_hash); - } else { - self.collection.insert(*envelope, folder_hash); } let ref_folders: FnvHashMap = self.backend.folders();