Utilize EnvelopeRemove events

EnvelopeRemove events were not ever used in the UI
async
Manos Pitsidianakis 2020-06-23 17:23:42 +03:00
parent efb06be09b
commit bfbaf3d617
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 19 additions and 8 deletions

View File

@ -1470,6 +1470,12 @@ impl Component for CompactListing {
self.view self.view
.process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context); .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) => { UIEvent::EnvelopeUpdate(ref env_hash) => {
let account = &context.accounts[self.cursor_pos.0]; let account = &context.accounts[self.cursor_pos.0];
let threads = &account.collection.threads[&self.cursor_pos.1]; let threads = &account.collection.threads[&self.cursor_pos.1];

View File

@ -629,25 +629,30 @@ impl Account {
Some(crate::types::NotificationType::NewMail), 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")] #[cfg(feature = "sqlite3")]
{ {
let envelopes = self.collection.envelopes.read(); let envelopes = self.collection.envelopes.read();
let envelopes = envelopes.unwrap(); let envelopes = envelopes.unwrap();
if let Err(err) = crate::sqlite3::remove(envelope_hash) { if let Err(err) = crate::sqlite3::remove(env_hash) {
melib::log( melib::log(
format!( format!(
"Failed to remove envelope {} [{}] in cache: {}", "Failed to remove envelope {} [{}] in cache: {}",
&envelopes[&envelope_hash].message_id_display(), &envelopes[&env_hash].message_id_display(),
envelope_hash, env_hash,
err.to_string() err.to_string()
), ),
melib::ERROR, melib::ERROR,
); );
} }
} }
self.collection.remove(envelope_hash, mailbox_hash); self.collection.remove(env_hash, mailbox_hash);
return Some(EnvelopeRemove(envelope_hash)); return Some(EnvelopeRemove(env_hash, thread_hash));
} }
RefreshEventKind::Rescan => { RefreshEventKind::Rescan => {
let handle = Account::new_worker( let handle = Account::new_worker(

View File

@ -39,7 +39,7 @@ use super::execute::Action;
use super::terminal::*; use super::terminal::*;
use melib::backends::{AccountHash, MailboxHash}; use melib::backends::{AccountHash, MailboxHash};
use melib::{EnvelopeHash, RefreshEvent}; use melib::{EnvelopeHash, RefreshEvent, ThreadHash};
use nix::unistd::Pid; use nix::unistd::Pid;
use std; use std;
use std::fmt; use std::fmt;
@ -119,7 +119,7 @@ pub enum UIEvent {
RefreshEvent(Box<RefreshEvent>), RefreshEvent(Box<RefreshEvent>),
EnvelopeUpdate(EnvelopeHash), EnvelopeUpdate(EnvelopeHash),
EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash
EnvelopeRemove(EnvelopeHash), EnvelopeRemove(EnvelopeHash, ThreadHash),
Contacts(ContactEvent), Contacts(ContactEvent),
Compose(ComposeEvent), Compose(ComposeEvent),
FinishedUIDialog(crate::components::ComponentId, UIMessage), FinishedUIDialog(crate::components::ComponentId, UIMessage),