Skip to content

Commit bc0018a

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): add type to represent time-based lock on event cache
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent 12292c5 commit bc0018a

File tree

1 file changed

+18
-0
lines changed
  • crates/matrix-sdk-indexeddb/src/event_cache_store

1 file changed

+18
-0
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,31 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License
1414

15+
use std::time::Duration;
16+
1517
use matrix_sdk_base::{
1618
deserialized_responses::TimelineEvent, event_cache::store::extract_event_relation,
1719
linked_chunk::ChunkIdentifier,
1820
};
1921
use ruma::{OwnedEventId, OwnedRoomId, RoomId};
2022
use serde::{Deserialize, Serialize};
2123

24+
/// Representation of a time-based lock on the entire
25+
/// [`IndexeddbEventCacheStore`](crate::event_cache_store::IndexeddbEventCacheStore)
26+
#[derive(Debug, Clone, Serialize, Deserialize)]
27+
pub struct Lease {
28+
pub key: String,
29+
pub holder: String,
30+
pub expiration: Duration,
31+
}
32+
33+
impl Lease {
34+
/// Determines whether the lease is expired at a given time `t`
35+
pub fn expired_at(&self, t: Duration) -> bool {
36+
self.expiration < t
37+
}
38+
}
39+
2240
/// Representation of a [`Chunk`](matrix_sdk_base::linked_chunk::Chunk)
2341
/// which can be stored in IndexedDB.
2442
#[derive(Debug, Serialize, Deserialize)]

0 commit comments

Comments
 (0)