Skip to main content

coven/
handle_sync_status.rs

1//! The sync state an app shows, read from coven's own rows (§19.1, E5).
2use crate::*;
3
4impl CovenHandle {
5    /// The sync state and when sync last finished, as `coven_sync_state`
6    /// shows them in one committed snapshot (§19.1). An app's screen reads
7    /// the view in its own live query instead.
8    pub async fn sync_status(&self) -> CovenResult<SyncStatus> {
9        coven_sync::sync_status(&self.database).await.map_err(CovenError::from)
10    }
11    /// Follow the sync state with a live query of `coven_sync_state`, as an
12    /// app does (E4, E5).
13    #[cfg(any(test, feature = "test-utils"))]
14    pub fn test_sync_status(&self) -> coven_database::test_utils::Followed<SyncStatus, CovenError> {
15        coven_database::test_utils::Followed::new(
16            self.database.subscribe(|sql| SyncStatus::read(sql).map_err(CovenError::from)),
17        )
18    }
19    /// Follow `coven_sync_status.last_pass` with a live query, as an app's
20    /// SQL does (E4): `None` until a pass ends on this device.
21    #[cfg(any(test, feature = "test-utils"))]
22    pub fn test_last_pass(
23        &self,
24    ) -> coven_database::test_utils::Followed<Option<LastPass>, DbError> {
25        LastPass::follow(&self.database)
26    }
27}
28
29#[cfg(test)]
30#[path = "handle_sync_status_tests.rs"]
31mod tests;