melib/threads: already-exists check in threads insert

async
Manos Pitsidianakis 2020-01-18 05:02:03 +02:00
parent 350fafb515
commit e07b5faf6e
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
6 changed files with 40 additions and 27 deletions

View File

@ -747,9 +747,17 @@ impl Threads {
{
return false;
}
let message_id = envelopes_lck[&env_hash].message_id().raw();
if self.message_ids.contains_key(message_id)
&& !self.missing_message_ids.contains(message_id)
{
return false;
}
let new_id = self
.message_ids
.get(envelopes_lck[&env_hash].message_id().raw())
.get(message_id)
.cloned()
.unwrap_or_else(|| ThreadNodeHash::new());
{

View File

@ -440,12 +440,15 @@ impl ListingTrait for CompactListing {
if !account.collection.contains_key(&env_hash) {
continue;
}
let env_hash_thread_hash = account.collection.get_env(env_hash).thread();
if !threads.thread_nodes.contains_key(&env_hash_thread_hash) {
let env_thread_node_hash = account.collection.get_env(env_hash).thread();
if !threads
.thread_nodes
.contains_key(&env_thread_node_hash)
{
continue;
}
let thread =
threads.find_group(threads.thread_nodes[&env_hash_thread_hash].group);
threads.find_group(threads.thread_nodes[&env_thread_node_hash].group);
if self.filtered_order.contains_key(&thread) {
continue;
}
@ -980,8 +983,8 @@ impl CompactListing {
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
let threads = &account.collection.threads[&folder_hash];
let thread = threads.thread_ref(thread_hash);
// FIXME: Thread root doesn't nessessarily have message set
if let Some(env_hash) = threads.thread_nodes()[&thread.root()].message() {
let thread_node_hash = threads.thread_group_iter(thread_hash).next().unwrap().1;
if let Some(env_hash) = threads.thread_nodes()[&thread_node_hash].message() {
if !account.contains_key(env_hash) {
/* The envelope has been renamed or removed, so wait for the appropriate event to
* arrive */
@ -1311,12 +1314,12 @@ impl Component for CompactListing {
if !account.collection.contains_key(&new_hash) {
return false;
}
let new_env_thread_hash = account.collection.get_env(*new_hash).thread();
if !threads.thread_nodes.contains_key(&new_env_thread_hash) {
let new_env_thread_node_hash = account.collection.get_env(*new_hash).thread();
if !threads.thread_nodes.contains_key(&new_env_thread_node_hash) {
return false;
}
let thread: ThreadHash =
threads.find_group(threads.thread_nodes()[&new_env_thread_hash].group);
threads.find_group(threads.thread_nodes()[&new_env_thread_node_hash].group);
if self.order.contains_key(&thread) {
self.row_updates.push(thread);
}

View File

@ -412,12 +412,12 @@ impl ListingTrait for ConversationsListing {
if !account.collection.contains_key(&env_hash) {
continue;
}
let env_hash_thread_hash = account.collection.get_env(env_hash).thread();
if !threads.thread_nodes.contains_key(&env_hash_thread_hash) {
let env_thread_node_hash = account.collection.get_env(env_hash).thread();
if !threads.thread_nodes.contains_key(&env_thread_node_hash) {
continue;
}
let thread =
threads.find_group(threads.thread_nodes[&env_hash_thread_hash].group);
threads.find_group(threads.thread_nodes[&env_thread_node_hash].group);
if self.filtered_order.contains_key(&thread) {
continue;
}
@ -922,10 +922,11 @@ impl ConversationsListing {
let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
let threads = &account.collection.threads[&folder_hash];
let thread = threads.thread_ref(thread_hash);
let thread_node_hash = threads.thread_group_iter(thread_hash).next().unwrap().1;
let idx: usize = self.order[&thread_hash];
let width = self.content.size().0;
let env_hash = threads.thread_nodes()[&thread.root()].message().unwrap();
let env_hash = threads.thread_nodes()[&thread_node_hash].message().unwrap();
let fg_color = if thread.unseen() > 0 {
Color::Byte(0)
@ -1206,12 +1207,12 @@ impl Component for ConversationsListing {
if !account.collection.contains_key(&new_hash) {
return false;
}
let new_env_thread_hash = account.collection.get_env(*new_hash).thread();
if !threads.thread_nodes.contains_key(&new_env_thread_hash) {
let env_thread_node_hash = account.collection.get_env(*new_hash).thread();
if !threads.thread_nodes.contains_key(&env_thread_node_hash) {
return false;
}
let thread: ThreadHash =
threads.find_group(threads.thread_nodes()[&new_env_thread_hash].group);
threads.find_group(threads.thread_nodes()[&env_thread_node_hash].group);
if self.order.contains_key(&thread) {
self.row_updates.push(thread);
}

View File

@ -62,7 +62,7 @@ pub struct PlainListing {
filtered_selection: Vec<EnvelopeHash>,
filtered_order: FnvHashMap<EnvelopeHash, usize>,
selection: FnvHashMap<EnvelopeHash, bool>,
thread_hashes: FnvHashMap<EnvelopeHash, ThreadNodeHash>,
thread_node_hashes: FnvHashMap<EnvelopeHash, ThreadNodeHash>,
local_collection: Vec<EnvelopeHash>,
/// If we must redraw on next redraw event
dirty: bool,
@ -90,7 +90,7 @@ impl MailListingTrait for PlainListing {
self.selection
.iter()
.filter(|(_, v)| **v)
.map(|(k, _)| self.thread_hashes[k])
.map(|(k, _)| self.thread_node_hashes[k])
.collect()
} else {
let mut ret = SmallVec::new();
@ -481,7 +481,7 @@ impl PlainListing {
subsort: (SortField::Date, SortOrder::Desc),
all_envelopes: fnv::FnvHashSet::default(),
local_collection: Vec::new(),
thread_hashes: FnvHashMap::default(),
thread_node_hashes: FnvHashMap::default(),
order: FnvHashMap::default(),
filter_term: String::new(),
filtered_selection: Vec::new(),
@ -606,7 +606,7 @@ impl PlainListing {
.envelopes
.read()
.unwrap();
self.thread_hashes = context.accounts[self.cursor_pos.0][folder_hash]
self.thread_node_hashes = context.accounts[self.cursor_pos.0][folder_hash]
.unwrap()
.envelopes
.iter()

View File

@ -323,8 +323,8 @@ impl ThreadListing {
let mut iter = threads.threads_iter().peekable();
/* This is just a desugared for loop so that we can use .peek() */
let mut idx = 0;
while let Some((indentation, thread_hash, has_sibling)) = iter.next() {
let thread_node = &thread_nodes[&thread_hash];
while let Some((indentation, thread_node_hash, has_sibling)) = iter.next() {
let thread_node = &thread_nodes[&thread_node_hash];
if indentation == 0 {
thread_idx += 1;
@ -350,7 +350,7 @@ impl ThreadListing {
&envelope,
idx,
indentation,
thread_hash,
thread_node_hash,
threads,
&indentations,
has_sibling,

View File

@ -168,16 +168,17 @@ impl ThreadView {
let thread_iter = threads.thread_group_iter(self.thread_group);
self.entries.clear();
for (line, (ind, thread_hash)) in thread_iter.enumerate() {
let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_hash].message() {
for (line, (ind, thread_node_hash)) in thread_iter.enumerate() {
let entry = if let Some(msg_hash) = threads.thread_nodes()[&thread_node_hash].message()
{
let seen: bool = account.collection.get_env(msg_hash).is_seen();
self.make_entry((ind, thread_hash, line), msg_hash, seen)
self.make_entry((ind, thread_node_hash, line), msg_hash, seen)
} else {
continue;
};
self.entries.push(entry);
match expanded_hash {
Some(expanded_hash) if expanded_hash == thread_hash => {
Some(expanded_hash) if expanded_hash == thread_node_hash => {
self.new_expanded_pos = self.entries.len().saturating_sub(1);
self.expanded_pos = self.new_expanded_pos + 1;
}