From 20f86f2741cb1d78c983b723cfc5f927846e7354 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 15 Jan 2020 12:41:31 +0200 Subject: ui/listing: add mailbox reload rate limit --- ui/src/components/mail/listing.rs | 30 ++++++++++++++++++++++++++++++ ui/src/conf/accounts.rs | 6 ++++++ 2 files changed, 36 insertions(+) (limited to 'ui') diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 420211a7..67c38233 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -238,6 +238,7 @@ pub struct Listing { dirty: bool, visible: bool, cursor_pos: (usize, usize), + startup_checks_rate: RateLimit, id: ComponentId, show_divider: bool, @@ -358,6 +359,34 @@ impl Component for Listing { self.dirty = false; } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { + match event { + UIEvent::StartupCheck(ref f) => { + if context.accounts[self.component.coordinates().0] + .folders_order + .get(self.component.coordinates().1) + .map(|&folder_hash| *f == folder_hash) + .unwrap_or(false) + { + if !self.startup_checks_rate.tick() { + return false; + } + } + } + UIEvent::Timer(n) if *n == self.startup_checks_rate.id() => { + if self.startup_checks_rate.active { + self.startup_checks_rate.reset(); + if let Some(folder_hash) = context.accounts[self.component.coordinates().0] + .folders_order + .get(self.component.coordinates().1) + { + return self + .process_event(&mut UIEvent::StartupCheck(*folder_hash), context); + } + } + } + _ => {} + } + if self.component.process_event(event, context) { return true; } @@ -811,6 +840,7 @@ impl Listing { visible: true, dirty: true, cursor_pos: (0, 0), + startup_checks_rate: RateLimit::new(2, 1000), id: ComponentId::new_v4(), show_divider: false, menu_visibility: true, diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 67df5e2a..de63ddba 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -847,6 +847,12 @@ impl Account { }; *f = MailboxEntry::Available(m); }); + self.sender + .send(ThreadEvent::UIEvent(UIEvent::MailboxUpdate(( + self.index, + folder_hash, + )))) + .unwrap(); self.workers.insert(folder_hash, None); } -- cgit v1.2.3