blob: da7ba535f9fec053a47b8bfeb6b9b3ae1aee4f88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
use axum::{
extract::{Request, State},
middleware::Next,
response::Response,
};
use crate::{app::App, clock::RequestedAt, error::Internal};
// Expires messages and conversations before each request.
pub async fn middleware<P>(
State(app): State<App<P>>,
RequestedAt(expired_at): RequestedAt,
req: Request,
next: Next,
) -> Result<Response, Internal>
where
P: Clone,
{
app.tokens().expire(&expired_at).await?;
app.invites().expire(&expired_at).await?;
app.messages().expire(&expired_at).await?;
app.messages().purge(&expired_at).await?;
app.conversations().expire(&expired_at).await?;
app.conversations().purge(&expired_at).await?;
Ok(next.run(req).await)
}
|