2021-02-20 00:10:05 +01:00
|
|
|
use std::error::Error;
|
2021-02-18 12:02:04 +01:00
|
|
|
|
2021-02-25 00:47:39 +01:00
|
|
|
use async_trait::async_trait;
|
2021-02-26 17:55:23 +01:00
|
|
|
use url::Url;
|
2021-02-28 18:00:37 +01:00
|
|
|
use chrono::{DateTime, Utc};
|
2021-02-18 12:02:04 +01:00
|
|
|
|
2021-02-25 00:47:39 +01:00
|
|
|
use crate::Calendar;
|
2021-02-18 12:02:04 +01:00
|
|
|
|
2021-02-25 00:47:39 +01:00
|
|
|
#[async_trait]
|
|
|
|
pub trait CalDavSource {
|
|
|
|
/// Returns the current calendars that this source contains
|
|
|
|
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
|
|
|
async fn get_calendars(&self) -> Result<&Vec<Calendar>, Box<dyn Error>>;
|
|
|
|
/// Returns the current calendars that this source contains
|
|
|
|
/// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server)
|
|
|
|
async fn get_calendars_mut(&mut self) -> Result<Vec<&mut Calendar>, Box<dyn Error>>;
|
2021-02-26 17:55:23 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// TODO: find a better search key (do calendars have a unique ID?)
|
|
|
|
// TODO: search key should be a reference
|
|
|
|
//
|
|
|
|
/// Returns the calendar matching the URL
|
|
|
|
async fn get_calendar(&self, url: Url) -> Option<&Calendar>;
|
|
|
|
/// Returns the calendar matching the URL
|
|
|
|
async fn get_calendar_mut(&mut self, url: Url) -> Option<&mut Calendar>;
|
|
|
|
|
2021-02-18 12:02:04 +01:00
|
|
|
}
|
2021-02-28 18:00:37 +01:00
|
|
|
|
|
|
|
pub trait SyncSlave {
|
|
|
|
/// Returns the last time this source successfully synced from a master source (e.g. from a server)
|
|
|
|
/// (or None in case it has never been synchronized)
|
|
|
|
fn get_last_sync(&self) -> Option<DateTime<Utc>>;
|
|
|
|
/// Update the last sync timestamp to now, or to a custom time in case `timepoint` is `Some`
|
|
|
|
fn update_last_sync(&mut self, timepoint: Option<DateTime<Utc>>);
|
|
|
|
}
|