Anki/rslib/src/collection/timestamps.rs
Damien Elmes 262b50445c start on making deck config and schema/mod changes undoable
+ move timestamps into a struct in a separate file for convenience
2021-04-18 17:33:12 +10:00

32 lines
1 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use crate::prelude::*;
pub(crate) struct CollectionTimestamps {
pub collection_change: TimestampMillis,
pub schema_change: TimestampMillis,
pub last_sync: TimestampMillis,
}
impl CollectionTimestamps {
pub fn collection_changed_since_sync(&self) -> bool {
self.collection_change > self.last_sync
}
pub fn schema_changed_since_sync(&self) -> bool {
self.schema_change > self.last_sync
}
}
impl Collection {
pub(crate) fn set_modified(&mut self) -> Result<()> {
let stamps = self.storage.get_collection_timestamps()?;
self.set_modified_time_undoable(TimestampMillis::now(), stamps.collection_change)
}
pub(crate) fn set_schema_modified(&mut self) -> Result<()> {
let stamps = self.storage.get_collection_timestamps()?;
self.set_schema_modified_time_undoable(TimestampMillis::now(), stamps.schema_change)
}
}