use rusmes_storage::{MailboxId, MetadataStore};
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)]
pub struct MailboxChanges {
pub exists: u32,
pub recent: u32,
}
impl MailboxChanges {
pub fn new(exists: u32, recent: u32) -> Self {
Self { exists, recent }
}
pub fn has_changes(&self, snapshot: &MailboxChanges) -> bool {
self.exists != snapshot.exists || self.recent != snapshot.recent
}
}
pub struct MailboxWatcher {
metadata_store: Arc<dyn MetadataStore>,
}
impl MailboxWatcher {
pub fn new(metadata_store: Arc<dyn MetadataStore>) -> Self {
Self { metadata_store }
}
pub async fn get_mailbox_state(
&self,
mailbox_id: &MailboxId,
) -> anyhow::Result<MailboxChanges> {
let counters = self.metadata_store.get_mailbox_counters(mailbox_id).await?;
Ok(MailboxChanges::new(counters.exists, counters.recent))
}
}