diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs index 6d56bee84..2a5ea8af0 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License +use std::time::Duration; + use matrix_sdk_base::{ deserialized_responses::TimelineEvent, event_cache::store::extract_event_relation, linked_chunk::ChunkIdentifier, @@ -19,6 +21,22 @@ use matrix_sdk_base::{ use ruma::{OwnedEventId, OwnedRoomId, RoomId}; use serde::{Deserialize, Serialize}; +/// Representation of a time-based lock on the entire +/// [`IndexeddbEventCacheStore`](crate::event_cache_store::IndexeddbEventCacheStore) +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Lease { + pub key: String, + pub holder: String, + pub expiration: Duration, +} + +impl Lease { + /// Determines whether the lease is expired at a given time `t` + pub fn expired_at(&self, t: Duration) -> bool { + self.expiration < t + } +} + /// Representation of a [`Chunk`](matrix_sdk_base::linked_chunk::Chunk) /// which can be stored in IndexedDB. #[derive(Debug, Serialize, Deserialize)]