Files
continuwuity/src/api/client/relations.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.5 KiB
Rust
Raw Normal View History

2024-07-16 08:05:25 +00:00
use axum::extract::State;
use ruma::api::client::relations::{
get_relating_events, get_relating_events_with_rel_type, get_relating_events_with_rel_type_and_event_type,
};
2023-06-25 19:31:40 +02:00
2024-07-16 08:05:25 +00:00
use crate::{Result, Ruma};
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
2024-04-22 23:48:57 -04:00
pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
2024-07-16 08:05:25 +00:00
State(services): State<crate::State>, body: Ruma<get_relating_events_with_rel_type_and_event_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type_and_event_type::v1::Response> {
2024-08-08 17:18:30 +00:00
let sender_user = body.sender_user.as_deref().expect("user is authenticated");
2024-03-05 19:48:54 -05:00
2024-08-08 17:18:30 +00:00
let res = services
.rooms
.pdu_metadata
.paginate_relations_with_filter(
sender_user,
&body.room_id,
&body.event_id,
body.event_type.clone().into(),
body.rel_type.clone().into(),
2024-10-31 23:39:20 +03:00
body.from.as_deref(),
body.to.as_deref(),
2024-08-08 17:18:30 +00:00
body.limit,
body.recurse,
body.dir,
)
.await?;
2024-03-05 19:48:54 -05:00
Ok(get_relating_events_with_rel_type_and_event_type::v1::Response {
chunk: res.chunk,
next_batch: res.next_batch,
prev_batch: res.prev_batch,
recursion_depth: res.recursion_depth,
})
}
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}`
2024-04-22 23:48:57 -04:00
pub(crate) async fn get_relating_events_with_rel_type_route(
2024-07-16 08:05:25 +00:00
State(services): State<crate::State>, body: Ruma<get_relating_events_with_rel_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type::v1::Response> {
2024-08-08 17:18:30 +00:00
let sender_user = body.sender_user.as_deref().expect("user is authenticated");
2024-03-05 19:48:54 -05:00
2024-08-08 17:18:30 +00:00
let res = services
.rooms
.pdu_metadata
.paginate_relations_with_filter(
sender_user,
&body.room_id,
&body.event_id,
None,
body.rel_type.clone().into(),
2024-10-31 23:39:20 +03:00
body.from.as_deref(),
body.to.as_deref(),
2024-08-08 17:18:30 +00:00
body.limit,
body.recurse,
body.dir,
)
.await?;
2024-03-05 19:48:54 -05:00
Ok(get_relating_events_with_rel_type::v1::Response {
chunk: res.chunk,
next_batch: res.next_batch,
prev_batch: res.prev_batch,
recursion_depth: res.recursion_depth,
})
}
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}`
2024-04-22 23:48:57 -04:00
pub(crate) async fn get_relating_events_route(
2024-07-16 08:05:25 +00:00
State(services): State<crate::State>, body: Ruma<get_relating_events::v1::Request>,
) -> Result<get_relating_events::v1::Response> {
2024-08-08 17:18:30 +00:00
let sender_user = body.sender_user.as_deref().expect("user is authenticated");
2024-03-05 19:48:54 -05:00
2024-08-08 17:18:30 +00:00
services
.rooms
.pdu_metadata
.paginate_relations_with_filter(
sender_user,
&body.room_id,
&body.event_id,
None,
None,
2024-10-31 23:39:20 +03:00
body.from.as_deref(),
body.to.as_deref(),
2024-08-08 17:18:30 +00:00
body.limit,
body.recurse,
body.dir,
)
.await
2023-06-25 19:31:40 +02:00
}