mirror of https://gitlab.com/famedly/conduit
feat: partially support sync filters
parent
68e910bb77
commit
1bd9fd74b3
@ -1,32 +1,47 @@
|
|||||||
use crate::{utils, ConduitResult};
|
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||||
use ruma::api::client::r0::filter::{self, create_filter, get_filter};
|
use ruma::api::client::{
|
||||||
|
error::ErrorKind,
|
||||||
|
r0::filter::{create_filter, get_filter},
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "conduit_bin")]
|
#[cfg(feature = "conduit_bin")]
|
||||||
use rocket::{get, post};
|
use rocket::{get, post};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
|
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
|
||||||
///
|
///
|
||||||
/// TODO: Loads a filter that was previously created.
|
/// Loads a filter that was previously created.
|
||||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/user/<_>/filter/<_>"))]
|
///
|
||||||
#[tracing::instrument]
|
/// - A user can only access their own filters
|
||||||
pub async fn get_filter_route() -> ConduitResult<get_filter::Response> {
|
#[cfg_attr(
|
||||||
// TODO
|
feature = "conduit_bin",
|
||||||
Ok(get_filter::Response::new(filter::IncomingFilterDefinition {
|
get("/_matrix/client/r0/user/<_>/filter/<_>", data = "<body>")
|
||||||
event_fields: None,
|
)]
|
||||||
event_format: filter::EventFormat::default(),
|
#[tracing::instrument(skip(db, body))]
|
||||||
account_data: filter::IncomingFilter::default(),
|
pub async fn get_filter_route(
|
||||||
room: filter::IncomingRoomFilter::default(),
|
db: DatabaseGuard,
|
||||||
presence: filter::IncomingFilter::default(),
|
body: Ruma<get_filter::Request<'_>>,
|
||||||
})
|
) -> ConduitResult<get_filter::Response> {
|
||||||
.into())
|
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::Response::new(filter).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
||||||
///
|
///
|
||||||
/// TODO: Creates a new filter to be used by other endpoints.
|
/// Creates a new filter to be used by other endpoints.
|
||||||
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/user/<_>/filter"))]
|
#[cfg_attr(
|
||||||
#[tracing::instrument]
|
feature = "conduit_bin",
|
||||||
pub async fn create_filter_route() -> ConduitResult<create_filter::Response> {
|
post("/_matrix/client/r0/user/<_>/filter", data = "<body>")
|
||||||
// TODO
|
)]
|
||||||
Ok(create_filter::Response::new(utils::random_string(10)).into())
|
#[tracing::instrument(skip(db, body))]
|
||||||
|
pub async fn create_filter_route(
|
||||||
|
db: DatabaseGuard,
|
||||||
|
body: Ruma<create_filter::Request<'_>>,
|
||||||
|
) -> ConduitResult<create_filter::Response> {
|
||||||
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
Ok(create_filter::Response::new(db.users.create_filter(sender_user, &body.filter)?).into())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue