diff --git a/crates/storage-pg/src/compat/session.rs b/crates/storage-pg/src/compat/session.rs index 1cdcd137..20c224e3 100644 --- a/crates/storage-pg/src/compat/session.rs +++ b/crates/storage-pg/src/compat/session.rs @@ -1,4 +1,4 @@ -// Copyright 2023 The Matrix.org Foundation C.I.C. +// Copyright 2023, 2024 The Matrix.org Foundation C.I.C. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -253,6 +253,14 @@ impl Filter for CompatSessionFilter<'_> { } } })) + .add_option(self.last_active_after().map(|last_active_after| { + Expr::col((CompatSessions::Table, CompatSessions::LastActiveAt)) + .gt(last_active_after) + })) + .add_option(self.last_active_before().map(|last_active_before| { + Expr::col((CompatSessions::Table, CompatSessions::LastActiveAt)) + .lt(last_active_before) + })) .add_option(self.device().map(|device| { Expr::col((CompatSessions::Table, CompatSessions::DeviceId)).eq(device.as_str()) })) diff --git a/crates/storage/src/compat/session.rs b/crates/storage/src/compat/session.rs index 8ee076f4..0b0ff4a9 100644 --- a/crates/storage/src/compat/session.rs +++ b/crates/storage/src/compat/session.rs @@ -1,4 +1,4 @@ -// Copyright 2023 The Matrix.org Foundation C.I.C. +// Copyright 2023, 2024 The Matrix.org Foundation C.I.C. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -70,6 +70,8 @@ pub struct CompatSessionFilter<'a> { state: Option, auth_type: Option, device: Option<&'a Device>, + last_active_before: Option>, + last_active_after: Option>, } impl<'a> CompatSessionFilter<'a> { @@ -118,6 +120,36 @@ impl<'a> CompatSessionFilter<'a> { self.browser_session } + /// Only return sessions with a last active time before the given time + #[must_use] + pub fn with_last_active_before(mut self, last_active_before: DateTime) -> Self { + self.last_active_before = Some(last_active_before); + self + } + + /// Only return sessions with a last active time after the given time + #[must_use] + pub fn with_last_active_after(mut self, last_active_after: DateTime) -> Self { + self.last_active_after = Some(last_active_after); + self + } + + /// Get the last active before filter + /// + /// Returns [`None`] if no client filter was set + #[must_use] + pub fn last_active_before(&self) -> Option> { + self.last_active_before + } + + /// Get the last active after filter + /// + /// Returns [`None`] if no client filter was set + #[must_use] + pub fn last_active_after(&self) -> Option> { + self.last_active_after + } + /// Only return active compatibility sessions #[must_use] pub fn active_only(mut self) -> Self {