imap: launch async watch when connection comes online

Closes #38 Make async watch/refresh work in imap
memfd
Manos Pitsidianakis 2020-07-05 20:11:47 +03:00
parent b5748c247a
commit 89dedbedb7
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 8 additions and 9 deletions

View File

@ -1419,7 +1419,7 @@ impl Account {
self.active_jobs.insert(job_id, JobRequest::IsOnline(rcvr)); self.active_jobs.insert(job_id, JobRequest::IsOnline(rcvr));
} }
} }
return self.backend.read().unwrap().is_online(); return Err(MeliError::new("Attempting connection."));
} else { } else {
let ret = self.backend.read().unwrap().is_online(); let ret = self.backend.read().unwrap().is_online();
if ret.is_ok() != self.is_online && ret.is_ok() { if ret.is_ok() != self.is_online && ret.is_ok() {
@ -1586,6 +1586,9 @@ impl Account {
if is_online.is_some() { if is_online.is_some() {
let is_online = is_online.unwrap(); let is_online = is_online.unwrap();
if is_online.is_ok() { if is_online.is_ok() {
if !self.is_online {
self.watch();
}
self.is_online = true; self.is_online = true;
self.sender self.sender
.send(ThreadEvent::UIEvent(UIEvent::AccountStatusChange( .send(ThreadEvent::UIEvent(UIEvent::AccountStatusChange(
@ -1603,6 +1606,9 @@ impl Account {
JobRequest::Refresh(_mailbox_hash, mut chan) => { JobRequest::Refresh(_mailbox_hash, mut chan) => {
let r = chan.try_recv().unwrap(); let r = chan.try_recv().unwrap();
if r.is_some() && r.unwrap().is_ok() { if r.is_some() && r.unwrap().is_ok() {
if !self.is_online {
self.watch();
}
self.is_online = true; self.is_online = true;
} }
self.sender self.sender

View File

@ -126,6 +126,7 @@ impl Context {
let ret = accounts[account_pos].is_online(); let ret = accounts[account_pos].is_online();
if ret.is_ok() { if ret.is_ok() {
if !was_online { if !was_online {
debug!("inserting mailbox hashes:");
for mailbox_node in accounts[account_pos].list_mailboxes() { for mailbox_node in accounts[account_pos].list_mailboxes() {
debug!( debug!(
"hash & mailbox: {:?} {}", "hash & mailbox: {:?} {}",
@ -133,13 +134,6 @@ impl Context {
accounts[account_pos][&mailbox_node.hash].name() accounts[account_pos][&mailbox_node.hash].name()
); );
} }
/* Account::watch() needs
* - work_controller to pass `work_context` to the watcher threads and then add them
* to the controller's static thread list,
* - sender to pass a RefreshEventConsumer closure to watcher threads for them to
* inform the main binary that refresh events arrived
* - replies to report any failures to the user
*/
accounts[account_pos].watch(); accounts[account_pos].watch();
replies.push_back(UIEvent::AccountStatusChange(account_pos)); replies.push_back(UIEvent::AccountStatusChange(account_pos));
@ -356,7 +350,6 @@ impl State {
} }
s.switch_to_alternate_screen(); s.switch_to_alternate_screen();
debug!("inserting mailbox hashes:");
for i in 0..s.context.accounts.len() { for i in 0..s.context.accounts.len() {
if !s.context.accounts[i].is_remote { if !s.context.accounts[i].is_remote {
s.context.accounts[i].watch(); s.context.accounts[i].watch();