mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-19 16:51:24 +01:00
implement rooms and not_rooms filters on /message
I really doubt anybody is sending /message requests with a filter that rejects the entire request, but it's the first step in the filter implementation.
This commit is contained in:
parent
a5e7ce6c33
commit
404d5fae6c
3 changed files with 116 additions and 1 deletions
|
|
@ -14,7 +14,9 @@ use ruma::{
|
|||
|
||||
use crate::{
|
||||
service::{pdu::PduBuilder, rooms::timeline::PduCount},
|
||||
services, utils, Ar, Error, Ra, Result,
|
||||
services, utils,
|
||||
utils::filter::CompiledRoomEventFilter,
|
||||
Ar, Error, Ra, Result,
|
||||
};
|
||||
|
||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}`
|
||||
|
|
@ -136,6 +138,13 @@ pub(crate) async fn get_message_events_route(
|
|||
let sender_device =
|
||||
body.sender_device.as_ref().expect("user is authenticated");
|
||||
|
||||
let Ok(filter) = CompiledRoomEventFilter::try_from(&body.filter) else {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"invalid 'filter' parameter",
|
||||
));
|
||||
};
|
||||
|
||||
let from = match body.from.clone() {
|
||||
Some(from) => PduCount::try_from_string(&from)?,
|
||||
None => match body.dir {
|
||||
|
|
@ -144,6 +153,15 @@ pub(crate) async fn get_message_events_route(
|
|||
},
|
||||
};
|
||||
|
||||
if !filter.room_allowed(&body.room_id) {
|
||||
return Ok(Ra(get_message_events::v3::Response {
|
||||
start: from.stringify(),
|
||||
end: None,
|
||||
chunk: vec![],
|
||||
state: vec![],
|
||||
}));
|
||||
}
|
||||
|
||||
let to = body.to.as_ref().and_then(|t| PduCount::try_from_string(t).ok());
|
||||
|
||||
services()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue