last_modified is no longer required
This commit is contained in:
parent
5c3c5c8090
commit
cbb4378581
6 changed files with 20 additions and 98 deletions
|
@ -33,15 +33,6 @@ impl CachedCalendar {
|
||||||
deleted_items: BTreeMap::new(),
|
deleted_items: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of tasks that this calendar contains
|
|
||||||
pub async fn get_tasks(&self) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>> {
|
|
||||||
self.get_tasks_modified_since(None).await
|
|
||||||
}
|
|
||||||
/// Returns the tasks that have been last-modified after `since`
|
|
||||||
pub async fn get_tasks_modified_since(&self, since: Option<DateTime<Utc>>) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>> {
|
|
||||||
self.get_items_modified_since(since, Some(SearchFilter::Tasks)).await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -106,43 +97,11 @@ impl PartialCalendar for CachedCalendar {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl CompleteCalendar for CachedCalendar {
|
impl CompleteCalendar for CachedCalendar {
|
||||||
/// Returns the items that have been deleted after `since`
|
|
||||||
async fn get_items_deleted_since(&self, since: DateTime<Utc>) -> Result<HashSet<ItemId>, Box<dyn Error>> {
|
|
||||||
Ok(self.deleted_items.range(since..)
|
|
||||||
.map(|(_key, id)| id.clone())
|
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the list of items that this calendar contains
|
/// Returns the list of items that this calendar contains
|
||||||
async fn get_items(&self) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>> {
|
async fn get_items(&self) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>> {
|
||||||
self.get_items_modified_since(None, None).await
|
Ok(self.items.iter()
|
||||||
}
|
.map(|(id, item)| (id.clone(), item))
|
||||||
|
.collect()
|
||||||
async fn get_items_modified_since(&self, since: Option<DateTime<Utc>>, filter: Option<SearchFilter>) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>> {
|
)
|
||||||
let filter = filter.unwrap_or_default();
|
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
|
||||||
|
|
||||||
for (_id, item) in &self.items {
|
|
||||||
match since {
|
|
||||||
None => (),
|
|
||||||
Some(since) => if item.last_modified() < since {
|
|
||||||
continue;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
match filter {
|
|
||||||
SearchFilter::Tasks => {
|
|
||||||
if item.is_task() == false {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
map.insert(item.id().clone(), item);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(map)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Calendar events
|
//! Calendar events
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use chrono::{Utc, DateTime};
|
|
||||||
|
|
||||||
use crate::item::ItemId;
|
use crate::item::ItemId;
|
||||||
use crate::item::SyncStatus;
|
use crate::item::SyncStatus;
|
||||||
|
@ -12,7 +11,6 @@ use crate::item::SyncStatus;
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
id: ItemId,
|
id: ItemId,
|
||||||
name: String,
|
name: String,
|
||||||
last_modified: DateTime<Utc>,
|
|
||||||
sync_status: SyncStatus,
|
sync_status: SyncStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +23,6 @@ impl Event {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_modified(&self) -> DateTime<Utc> {
|
|
||||||
self.last_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sync_status(&self) -> &SyncStatus {
|
pub fn sync_status(&self) -> &SyncStatus {
|
||||||
&self.sync_status
|
&self.sync_status
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ use std::fmt::{Display, Formatter};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use chrono::{Utc, DateTime};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::resource::Resource;
|
use crate::resource::Resource;
|
||||||
|
@ -30,13 +29,6 @@ impl Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_modified(&self) -> DateTime<Utc> {
|
|
||||||
match self {
|
|
||||||
Item::Event(e) => e.last_modified(),
|
|
||||||
Item::Task(t) => t.last_modified(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sync_status(&self) -> &SyncStatus {
|
pub fn sync_status(&self) -> &SyncStatus {
|
||||||
match self {
|
match self {
|
||||||
Item::Event(e) => e.sync_status(),
|
Item::Event(e) => e.sync_status(),
|
||||||
|
|
10
src/task.rs
10
src/task.rs
|
@ -1,4 +1,3 @@
|
||||||
use chrono::{Utc, DateTime};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::item::ItemId;
|
use crate::item::ItemId;
|
||||||
|
@ -10,8 +9,6 @@ pub struct Task {
|
||||||
/// The task unique ID, that will never change
|
/// The task unique ID, that will never change
|
||||||
id: ItemId,
|
id: ItemId,
|
||||||
|
|
||||||
/// The last modification date of this task
|
|
||||||
last_modified: DateTime<Utc>,
|
|
||||||
/// The sync status of this item
|
/// The sync status of this item
|
||||||
sync_status: SyncStatus,
|
sync_status: SyncStatus,
|
||||||
|
|
||||||
|
@ -23,11 +20,10 @@ pub struct Task {
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
/// Create a new Task
|
/// Create a new Task
|
||||||
pub fn new(name: String, id: ItemId, last_modified: DateTime<Utc>, sync_status: SyncStatus) -> Self {
|
pub fn new(name: String, id: ItemId, sync_status: SyncStatus) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
last_modified,
|
|
||||||
sync_status,
|
sync_status,
|
||||||
completed: false,
|
completed: false,
|
||||||
}
|
}
|
||||||
|
@ -36,27 +32,23 @@ impl Task {
|
||||||
pub fn id(&self) -> &ItemId { &self.id }
|
pub fn id(&self) -> &ItemId { &self.id }
|
||||||
pub fn name(&self) -> &str { &self.name }
|
pub fn name(&self) -> &str { &self.name }
|
||||||
pub fn completed(&self) -> bool { self.completed }
|
pub fn completed(&self) -> bool { self.completed }
|
||||||
pub fn last_modified(&self) -> DateTime<Utc> { self.last_modified }
|
|
||||||
pub fn sync_status(&self) -> &SyncStatus { &self.sync_status }
|
pub fn sync_status(&self) -> &SyncStatus { &self.sync_status }
|
||||||
pub fn set_sync_status(&mut self, new_status: SyncStatus) {
|
pub fn set_sync_status(&mut self, new_status: SyncStatus) {
|
||||||
self.sync_status = new_status;
|
self.sync_status = new_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_last_modified(&mut self) {
|
fn update_last_modified(&mut self) {
|
||||||
self.last_modified = Utc::now();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rename a task.
|
/// Rename a task.
|
||||||
/// This updates its "last modified" field
|
/// This updates its "last modified" field
|
||||||
pub fn set_name(&mut self, new_name: String) {
|
pub fn set_name(&mut self, new_name: String) {
|
||||||
self.update_last_modified();
|
|
||||||
self.name = new_name;
|
self.name = new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_completed(&mut self, new_value: bool) {
|
pub fn set_completed(&mut self, new_value: bool) {
|
||||||
// TODO: either require a reference to the DataSource, so that it is aware
|
// TODO: either require a reference to the DataSource, so that it is aware
|
||||||
// or change a flag here, and the DataSource will be able to check the flags of all its content (but then the Calendar should only give a reference/Arc, not a clone)
|
// or change a flag here, and the DataSource will be able to check the flags of all its content (but then the Calendar should only give a reference/Arc, not a clone)
|
||||||
self.update_last_modified();
|
|
||||||
self.completed = new_value;
|
self.completed = new_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
|
|
||||||
use crate::item::Item;
|
use crate::item::Item;
|
||||||
use crate::item::ItemId;
|
use crate::item::ItemId;
|
||||||
|
@ -79,15 +78,6 @@ pub trait PartialCalendar {
|
||||||
/// Usually, this is a calendar fully stored on a local disk
|
/// Usually, this is a calendar fully stored on a local disk
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait CompleteCalendar : PartialCalendar {
|
pub trait CompleteCalendar : PartialCalendar {
|
||||||
/// Returns the items that have been deleted after `since`
|
|
||||||
///
|
|
||||||
/// See also [`PartialCalendar::get_items_deleted_since`]
|
|
||||||
async fn get_items_deleted_since(&self, since: DateTime<Utc>) -> Result<HashSet<ItemId>, Box<dyn Error>>;
|
|
||||||
|
|
||||||
/// Returns the items that have been last-modified after `since`
|
|
||||||
async fn get_items_modified_since(&self, since: Option<DateTime<Utc>>, filter: Option<crate::calendar::SearchFilter>)
|
|
||||||
-> Result<HashMap<ItemId, &Item>, Box<dyn Error>>;
|
|
||||||
|
|
||||||
/// Returns the list of items that this calendar contains
|
/// Returns the list of items that this calendar contains
|
||||||
async fn get_items(&self) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>>;
|
async fn get_items(&self) -> Result<HashMap<ItemId, &Item>, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use chrono::{Utc, TimeZone};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use my_tasks::traits::CalDavSource;
|
use my_tasks::traits::CalDavSource;
|
||||||
|
@ -56,23 +55,19 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
||||||
|
|
||||||
let cal_id = Url::parse("http://todo.list/cal").unwrap();
|
let cal_id = Url::parse("http://todo.list/cal").unwrap();
|
||||||
|
|
||||||
let task_a = Item::Task(Task::new("task A".into(), ItemId::random(), Utc.ymd(2000, 1, 1).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_a = Item::Task(Task::new("task A".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_b = Item::Task(Task::new("task B".into(), ItemId::random(), Utc.ymd(2000, 1, 2).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_b = Item::Task(Task::new("task B".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_c = Item::Task(Task::new("task C".into(), ItemId::random(), Utc.ymd(2000, 1, 3).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_c = Item::Task(Task::new("task C".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_d = Item::Task(Task::new("task D".into(), ItemId::random(), Utc.ymd(2000, 1, 4).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_d = Item::Task(Task::new("task D".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_e = Item::Task(Task::new("task E".into(), ItemId::random(), Utc.ymd(2000, 1, 5).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_e = Item::Task(Task::new("task E".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_f = Item::Task(Task::new("task F".into(), ItemId::random(), Utc.ymd(2000, 1, 6).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_f = Item::Task(Task::new("task F".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_g = Item::Task(Task::new("task G".into(), ItemId::random(), Utc.ymd(2000, 1, 7).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_g = Item::Task(Task::new("task G".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_h = Item::Task(Task::new("task H".into(), ItemId::random(), Utc.ymd(2000, 1, 8).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_h = Item::Task(Task::new("task H".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_i = Item::Task(Task::new("task I".into(), ItemId::random(), Utc.ymd(2000, 1, 9).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_i = Item::Task(Task::new("task I".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_j = Item::Task(Task::new("task J".into(), ItemId::random(), Utc.ymd(2000, 1, 10).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_j = Item::Task(Task::new("task J".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_k = Item::Task(Task::new("task K".into(), ItemId::random(), Utc.ymd(2000, 1, 11).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_k = Item::Task(Task::new("task K".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_l = Item::Task(Task::new("task L".into(), ItemId::random(), Utc.ymd(2000, 1, 12).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_l = Item::Task(Task::new("task L".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
let task_m = Item::Task(Task::new("task M".into(), ItemId::random(), Utc.ymd(2000, 1, 12).and_hms(0, 0, 0), SyncStatus::random_synced()));
|
let task_m = Item::Task(Task::new("task M".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
|
|
||||||
// let last_sync = task_m.last_modified();
|
|
||||||
// local.update_last_sync(Some(last_sync));
|
|
||||||
// assert!(last_sync < Utc::now());
|
|
||||||
|
|
||||||
let task_b_id = task_b.id().clone();
|
let task_b_id = task_b.id().clone();
|
||||||
let task_c_id = task_c.id().clone();
|
let task_c_id = task_c.id().clone();
|
||||||
|
@ -132,7 +127,7 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
||||||
|
|
||||||
cal_server.delete_item(&task_l_id).await.unwrap();
|
cal_server.delete_item(&task_l_id).await.unwrap();
|
||||||
|
|
||||||
let task_n = Item::Task(Task::new("task N (new from server)".into(), ItemId::random(), Utc::now(), SyncStatus::random_synced()));
|
let task_n = Item::Task(Task::new("task N (new from server)".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||||
cal_server.add_item(task_n).await;
|
cal_server.add_item(task_n).await;
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,7 +156,7 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
||||||
cal_local.delete_item(&task_k_id).await.unwrap();
|
cal_local.delete_item(&task_k_id).await.unwrap();
|
||||||
cal_local.delete_item(&task_l_id).await.unwrap();
|
cal_local.delete_item(&task_l_id).await.unwrap();
|
||||||
|
|
||||||
let task_o = Item::Task(Task::new("task O (new from local)".into(), ItemId::random(), Utc::now(), SyncStatus::NotSynced));
|
let task_o = Item::Task(Task::new("task O (new from local)".into(), ItemId::random(), SyncStatus::NotSynced));
|
||||||
cal_local.add_item(task_o).await;
|
cal_local.add_item(task_o).await;
|
||||||
|
|
||||||
Provider::new(server, local)
|
Provider::new(server, local)
|
||||||
|
|
Loading…
Add table
Reference in a new issue