From b6c0236d24a6252aad0e6f14b5a5f41052ed854d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 6 Jun 2019 00:27:40 +0300 Subject: [PATCH] ui: make EnvelopeRename event not folder specific And pass EnvelopeRename events to subviews --- ui/src/components/mail/listing/compact.rs | 9 +++---- ui/src/components/mail/view.rs | 32 ++++++++++------------- ui/src/components/mail/view/thread.rs | 21 +++++++++++---- ui/src/conf/accounts.rs | 2 +- ui/src/types.rs | 2 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index d43a08d38..dad12fde7 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -646,10 +646,7 @@ impl Component for MailboxView { self.refresh_mailbox(context); self.set_dirty(); } - UIEvent::EnvelopeRename(ref folder_hash, ref old_hash, ref new_hash) - if *folder_hash - == context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] => - { + UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => { if let Some(row) = self.order.remove(old_hash) { self.order.insert(*new_hash, row); self.highlight_line(None, ((0, row), (MAX_COLS - 1, row)), row, context); @@ -658,6 +655,8 @@ impl Component for MailboxView { } else { /* Listing has was updated in time before the event */ } + self.view + .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context); } UIEvent::ChangeMode(UIMode::Normal) => { self.dirty = true; @@ -872,7 +871,7 @@ impl Component for CompactListing { | UIEvent::ComponentKill(_) | UIEvent::StartupCheck(_) | UIEvent::EnvelopeUpdate(_) - | UIEvent::EnvelopeRename(_, _, _) + | UIEvent::EnvelopeRename(_, _) | UIEvent::EnvelopeRemove(_) => { return self.views[self.cursor].process_event(event, context) } diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 461586a71..c787aae03 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -88,23 +88,6 @@ impl MailView { subview: Option>, context: &mut Context, ) -> Self { - let account = &mut context.accounts[coordinates.0]; - let (hash, is_seen) = { - let envelope: &Envelope = &account.get_env(&coordinates.2); - (envelope.hash(), envelope.is_seen()) - }; - if !is_seen { - let folder_hash = { - let mailbox = &mut account[coordinates.1].as_mut().unwrap(); - mailbox.folder.hash() - }; - let op = { - let backend = &account.backend; - backend.operation(hash, folder_hash) - }; - let envelope: &mut Envelope = &mut account.get_env_mut(&coordinates.2); - envelope.set_seen(op).unwrap(); - } MailView { coordinates, pager, @@ -304,6 +287,19 @@ impl Component for MailView { * arrive */ return; } + let (hash, is_seen) = { + let envelope: &Envelope = &account.get_env(&self.coordinates.2); + (envelope.hash(), envelope.is_seen()) + }; + if !is_seen { + let folder_hash = { + let mailbox = &mut account[self.coordinates.1].as_mut().unwrap(); + mailbox.folder.hash() + }; + let op = account.operation(&hash); + let envelope: &mut Envelope = &mut account.get_env_mut(&self.coordinates.2); + envelope.set_seen(op).unwrap(); + } let envelope: &Envelope = &account.get_env(&self.coordinates.2); if self.mode == ViewMode::Raw { @@ -746,7 +742,7 @@ impl Component for MailView { } self.dirty = true; } - UIEvent::EnvelopeRename(_, old_hash, new_hash) if old_hash == self.coordinates.2 => { + UIEvent::EnvelopeRename(old_hash, new_hash) => { self.coordinates.2 = new_hash; } _ => { diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 4b8be3684..7b1fca8cc 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -291,8 +291,7 @@ impl ThreadView { /* Box character drawing stuff */ let mut x = 0; for i in 0..e.index.0 { - let color = - INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())]; + let color = INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())]; change_colors( &mut content, ((x, 2 * y), (x + 3, 2 * y + 1)), @@ -408,6 +407,7 @@ impl ThreadView { /// draw the list fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { + /* Make space on the left for the scrollbar */ let mut upper_left = pos_inc(upper_left!(area), (1, 0)); let bottom_right = bottom_right!(area); let (width, height) = self.content.size(); @@ -613,9 +613,11 @@ impl ThreadView { let i = if let Some(i) = thread_node.message() { i } else { - threads.thread_nodes()[&thread_node.children()[0]] - .message() - .unwrap() + let mut iter_ptr = thread_node.children()[0]; + while threads.thread_nodes()[&iter_ptr].message().is_none() { + iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0]; + } + threads.thread_nodes()[&iter_ptr].message().unwrap() }; let envelope: &Envelope = account.get_env(&i); @@ -1013,6 +1015,15 @@ impl Component for ThreadView { UIEvent::Resize => { self.set_dirty(); } + UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => { + for e in self.entries.iter_mut() { + if e.msg_hash == *old_hash { + e.msg_hash = *new_hash; + } + } + self.mailview + .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context); + } _ => { if self.mailview.process_event(event, context) { return true; diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 83d64ec0b..8d6a2b2c3 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -314,7 +314,7 @@ impl Account { let mailbox = mailbox!(&folder_hash, self.folders); mailbox.rename(old_hash, new_hash); self.collection.rename(old_hash, new_hash, folder_hash); - return Some(EnvelopeRename(mailbox.folder.hash(), old_hash, new_hash)); + return Some(EnvelopeRename(old_hash, new_hash)); } RefreshEventKind::Create(envelope) => { let env_hash = envelope.hash(); diff --git a/ui/src/types.rs b/ui/src/types.rs index b1a6c4314..75413e421 100644 --- a/ui/src/types.rs +++ b/ui/src/types.rs @@ -87,7 +87,7 @@ pub enum UIEvent { StartupCheck(FolderHash), RefreshEvent(Box), EnvelopeUpdate(EnvelopeHash), - EnvelopeRename(FolderHash, EnvelopeHash, EnvelopeHash), // folder_hash, old_hash, new_hash + EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash EnvelopeRemove(EnvelopeHash), }