melib/jmap: impl watch() with polling

Concerns #22
lazy_fetch
Manos Pitsidianakis 2021-01-05 19:18:45 +02:00
parent 613c3de3d2
commit 50cd81772f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 26 additions and 1 deletions

View File

@ -341,7 +341,32 @@ impl MailBackend for JmapType {
}
fn watch(&self) -> ResultFuture<()> {
Err(MeliError::from("JMAP watch for updates is unimplemented"))
let connection = self.connection.clone();
let store = self.store.clone();
Ok(Box::pin(async move {
{
let mut conn = connection.lock().await;
conn.connect().await?;
}
loop {
{
let mailbox_hashes = {
store
.mailboxes
.read()
.unwrap()
.keys()
.cloned()
.collect::<SmallVec<[MailboxHash; 16]>>()
};
let conn = connection.lock().await;
for mailbox_hash in mailbox_hashes {
conn.email_changes(mailbox_hash).await?;
}
}
crate::connections::sleep(std::time::Duration::from_secs(60)).await;
}
}))
}
fn mailboxes(&self) -> ResultFuture<HashMap<MailboxHash, Mailbox>> {