mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
Add sync_changes to CalendarStore
This commit is contained in:
@@ -32,7 +32,7 @@ impl TryFrom<EventRow> for Event {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, sqlx::Type)]
|
||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
enum CalendarChangeOperation {
|
||||
// There's no distinction between Add and Modify
|
||||
@@ -308,6 +308,47 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn sync_changes(
|
||||
&self,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
synctoken: i64,
|
||||
) -> Result<(Vec<Event>, Vec<String>, i64), Error> {
|
||||
struct Row {
|
||||
uid: String,
|
||||
synctoken: i64,
|
||||
}
|
||||
let changes = sqlx::query_as!(
|
||||
Row,
|
||||
r#"
|
||||
SELECT DISTINCT uid, max(0, synctoken) as "synctoken!: i64" from eventchangelog
|
||||
WHERE synctoken > ?
|
||||
ORDER BY synctoken ASC
|
||||
"#,
|
||||
synctoken
|
||||
)
|
||||
.fetch_all(&self.db)
|
||||
.await?;
|
||||
|
||||
let mut events = vec![];
|
||||
let mut deleted_events = vec![];
|
||||
|
||||
let new_synctoken = changes
|
||||
.last()
|
||||
.map(|&Row { synctoken, .. }| synctoken)
|
||||
.unwrap_or(0);
|
||||
|
||||
for Row { uid, .. } in changes {
|
||||
match self.get_event(principal, cid, &uid).await {
|
||||
Ok(event) => events.push(event),
|
||||
Err(Error::NotFound) => deleted_events.push(uid),
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
Ok((events, deleted_events, new_synctoken))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_db_pool(db_url: &str, migrate: bool) -> anyhow::Result<Pool<Sqlite>> {
|
||||
|
||||
Reference in New Issue
Block a user