implement contains_url filter for /message

The plan is to move all of the per-event checks into the
pdu_event_allowed function.

TODO: split the `visibility_filter` function into it's own commit. I
think this one was inherited from an earlier conduwuit commit.
This commit is contained in:
Benjamin Lee 2024-05-02 18:46:58 -07:00
parent 2bcd357db2
commit 0e2694a6c4
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
2 changed files with 50 additions and 22 deletions

View file

@ -9,14 +9,14 @@ use ruma::{
message::{get_message_events, send_message_event},
},
events::{StateEventType, TimelineEventType},
uint, UInt,
uint, RoomId, UInt, UserId,
};
use crate::{
service::{pdu::PduBuilder, rooms::timeline::PduCount},
services, utils,
utils::filter::{load_limit, CompiledRoomEventFilter},
Ar, Error, Ra, Result,
Ar, Error, PduEvent, Ra, Result,
};
/// # `PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}`
@ -197,15 +197,8 @@ pub(crate) async fn get_message_events_route(
.take(load_limit(limit))
.filter_map(Result::ok)
.filter(|(_, pdu)| {
services()
.rooms
.state_accessor
.user_can_see_event(
sender_user,
&body.room_id,
&pdu.event_id,
)
.unwrap_or(false)
filter.pdu_event_allowed(pdu)
&& visibility_filter(pdu, sender_user, &body.room_id)
})
.take_while(|&(k, _)| Some(k) != to)
.take(limit)
@ -254,15 +247,8 @@ pub(crate) async fn get_message_events_route(
.take(load_limit(limit))
.filter_map(Result::ok)
.filter(|(_, pdu)| {
services()
.rooms
.state_accessor
.user_can_see_event(
sender_user,
&body.room_id,
&pdu.event_id,
)
.unwrap_or(false)
filter.pdu_event_allowed(pdu)
&& visibility_filter(pdu, sender_user, &body.room_id)
})
.take_while(|&(k, _)| Some(k) != to)
.take(limit)
@ -331,3 +317,15 @@ pub(crate) async fn get_message_events_route(
Ok(Ra(resp))
}
fn visibility_filter(
pdu: &PduEvent,
user_id: &UserId,
room_id: &RoomId,
) -> bool {
services()
.rooms
.state_accessor
.user_can_see_event(user_id, room_id, &pdu.event_id)
.unwrap_or(false)
}