You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
storage: add a filter by last active time on app sessions
This commit is contained in:
@@ -239,6 +239,16 @@ fn split_filter(
|
|||||||
oauth2_filter = oauth2_filter.for_browser_session(browser_session);
|
oauth2_filter = oauth2_filter.for_browser_session(browser_session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(last_active_before) = filter.last_active_before() {
|
||||||
|
compat_filter = compat_filter.with_last_active_before(last_active_before);
|
||||||
|
oauth2_filter = oauth2_filter.with_last_active_before(last_active_before);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(last_active_after) = filter.last_active_after() {
|
||||||
|
compat_filter = compat_filter.with_last_active_after(last_active_after);
|
||||||
|
oauth2_filter = oauth2_filter.with_last_active_after(last_active_after);
|
||||||
|
}
|
||||||
|
|
||||||
(compat_filter, oauth2_filter)
|
(compat_filter, oauth2_filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
//! Repositories to interact with all kinds of sessions
|
//! Repositories to interact with all kinds of sessions
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use mas_data_model::{BrowserSession, CompatSession, Device, Session, User};
|
use mas_data_model::{BrowserSession, CompatSession, Device, Session, User};
|
||||||
|
|
||||||
use crate::{repository_impl, Page, Pagination};
|
use crate::{repository_impl, Page, Pagination};
|
||||||
@@ -59,6 +60,8 @@ pub struct AppSessionFilter<'a> {
|
|||||||
browser_session: Option<&'a BrowserSession>,
|
browser_session: Option<&'a BrowserSession>,
|
||||||
state: Option<AppSessionState>,
|
state: Option<AppSessionState>,
|
||||||
device_id: Option<&'a Device>,
|
device_id: Option<&'a Device>,
|
||||||
|
last_active_before: Option<DateTime<Utc>>,
|
||||||
|
last_active_after: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AppSessionFilter<'a> {
|
impl<'a> AppSessionFilter<'a> {
|
||||||
@@ -107,6 +110,36 @@ impl<'a> AppSessionFilter<'a> {
|
|||||||
self.device_id
|
self.device_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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<Utc>) -> 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<Utc>) -> 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<DateTime<Utc>> {
|
||||||
|
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<DateTime<Utc>> {
|
||||||
|
self.last_active_after
|
||||||
|
}
|
||||||
|
|
||||||
/// Only return active compatibility sessions
|
/// Only return active compatibility sessions
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn active_only(mut self) -> Self {
|
pub fn active_only(mut self) -> Self {
|
||||||
|
Reference in New Issue
Block a user