From bfbaf3d61721d03738366dee2f5b3c768b4b7a36 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 23 Jun 2020 17:23:42 +0300 Subject: [PATCH] Utilize EnvelopeRemove events EnvelopeRemove events were not ever used in the UI --- src/components/mail/listing/compact.rs | 6 ++++++ src/conf/accounts.rs | 17 +++++++++++------ src/types.rs | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index 234711cf..c4f48252 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -1470,6 +1470,12 @@ impl Component for CompactListing { self.view .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context); } + UIEvent::EnvelopeRemove(ref _env_hash, ref thread_hash) => { + if self.order.contains_key(thread_hash) { + self.refresh_mailbox(context, false); + self.set_dirty(true); + } + } UIEvent::EnvelopeUpdate(ref env_hash) => { let account = &context.accounts[self.cursor_pos.0]; let threads = &account.collection.threads[&self.cursor_pos.1]; diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 1531fd6e..ae000bde 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -629,25 +629,30 @@ impl Account { Some(crate::types::NotificationType::NewMail), )); } - RefreshEventKind::Remove(envelope_hash) => { + RefreshEventKind::Remove(env_hash) => { + let thread_hash = { + let thread_hash = self.collection.get_env(env_hash).thread(); + self.collection.threads[&mailbox_hash] + .find_group(self.collection.threads[&mailbox_hash][&thread_hash].group) + }; #[cfg(feature = "sqlite3")] { let envelopes = self.collection.envelopes.read(); let envelopes = envelopes.unwrap(); - if let Err(err) = crate::sqlite3::remove(envelope_hash) { + if let Err(err) = crate::sqlite3::remove(env_hash) { melib::log( format!( "Failed to remove envelope {} [{}] in cache: {}", - &envelopes[&envelope_hash].message_id_display(), - envelope_hash, + &envelopes[&env_hash].message_id_display(), + env_hash, err.to_string() ), melib::ERROR, ); } } - self.collection.remove(envelope_hash, mailbox_hash); - return Some(EnvelopeRemove(envelope_hash)); + self.collection.remove(env_hash, mailbox_hash); + return Some(EnvelopeRemove(env_hash, thread_hash)); } RefreshEventKind::Rescan => { let handle = Account::new_worker( diff --git a/src/types.rs b/src/types.rs index 27170437..08244d4e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -39,7 +39,7 @@ use super::execute::Action; use super::terminal::*; use melib::backends::{AccountHash, MailboxHash}; -use melib::{EnvelopeHash, RefreshEvent}; +use melib::{EnvelopeHash, RefreshEvent, ThreadHash}; use nix::unistd::Pid; use std; use std::fmt; @@ -119,7 +119,7 @@ pub enum UIEvent { RefreshEvent(Box), EnvelopeUpdate(EnvelopeHash), EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash - EnvelopeRemove(EnvelopeHash), + EnvelopeRemove(EnvelopeHash, ThreadHash), Contacts(ContactEvent), Compose(ComposeEvent), FinishedUIDialog(crate::components::ComponentId, UIMessage),