mirror of https://gitlab.com/famedly/conduit
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
|
use ruma::api::client::{
|
|
error::ErrorKind,
|
|
filter::{create_filter, get_filter},
|
|
};
|
|
|
|
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
|
|
///
|
|
/// Loads a filter that was previously created.
|
|
///
|
|
/// - A user can only access their own filters
|
|
pub async fn get_filter_route(
|
|
db: DatabaseGuard,
|
|
body: Ruma<get_filter::v3::Request<'_>>,
|
|
) -> Result<get_filter::v3::Response> {
|
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
|
let filter = match db.users.get_filter(sender_user, &body.filter_id)? {
|
|
Some(filter) => filter,
|
|
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Filter not found.")),
|
|
};
|
|
|
|
Ok(get_filter::v3::Response::new(filter))
|
|
}
|
|
|
|
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
|
///
|
|
/// Creates a new filter to be used by other endpoints.
|
|
pub async fn create_filter_route(
|
|
db: DatabaseGuard,
|
|
body: Ruma<create_filter::v3::Request<'_>>,
|
|
) -> Result<create_filter::v3::Response> {
|
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
|
Ok(create_filter::v3::Response::new(
|
|
db.users.create_filter(sender_user, &body.filter)?,
|
|
))
|
|
}
|